@@ -8,8 +8,8 @@ The Asset Component
8
8
The Asset component manages URL generation and versioning of web assets such
9
9
as CSS stylesheets, JavaScript files and image files.
10
10
11
- In the past, it was common for web applications to hardcode the URLs of the web
12
- assets. For example:
11
+ In the past, it was common for web applications to hardcode URLs of web assets.
12
+ For example:
13
13
14
14
.. code-block :: html
15
15
@@ -20,23 +20,23 @@ assets. For example:
20
20
<a href =" /" ><img src =" /images/logo.png" ></a >
21
21
22
22
This practice is no longer recommended unless the web application is extremely
23
- simple. The main problems of hardcoding asset URLs are the following :
23
+ simple. Hardcoding URLs can be a disadvantage because :
24
24
25
- * **Templates get verbose ** because you have to write the full path for each
25
+ * **Templates get verbose **: you have to write the full path for each
26
26
asset. When using the Asset component, you can group assets in packages to
27
- avoid repeating the common part of their path.
28
- * **Versioning is difficult ** because it has to be custom managed for each
27
+ avoid repeating the common part of their path;
28
+ * **Versioning is difficult **: it has to be custom managed for each
29
29
application. Adding a version to the asset URLs is essential for some applications
30
30
because it allows to control how the assets are cached. The Asset component
31
- allows to define different versioning strategies for each package.
32
- * **Moving assets location ** is cumbersome and error-prone, because it requires
33
- you to carefully update the URLs of all assets included in all templates.
34
- The Asset component allows to move assets effortlessly just by changing the
35
- base path value associated with the package of assets.
36
- * **Impossible to use multiple CDNs ** because it requires to change the URL of
37
- the asset randomly for each request. The Asset component provides out-of-the-box
38
- support for any number of multiple CDNs, both regular (`` http:// ``) and
39
- secure (``https:// ``).
31
+ allows to define different versioning strategies for each package;
32
+ * **Moving assets location ** is cumbersome and error-prone: it requires you to
33
+ carefully update the URLs of all assets included in all templates. The Asset
34
+ component allows to move assets effortlessly just by changing the base path
35
+ value associated with the package of assets;
36
+ * **It's nearly impossible to use multiple CDNs **: this technique requires to
37
+ change the URL of the asset randomly for each request. The Asset component
38
+ provides out-of-the-box support for any number of multiple CDNs, both regular
39
+ (`` http:// ``) and secure (``https:// ``).
40
40
41
41
Installation
42
42
------------
@@ -117,8 +117,9 @@ Custom Version Strategies
117
117
.........................
118
118
119
119
Use the :class: `Symfony\\ Component\\ Asset\\ VersionStrategy\\ VersionStrategyInterface `
120
- to define your own version strategy. For example, you could define a versioning
121
- where the current date is a
8000
ppended to bust the cache every day::
120
+ to define your own versioning strategy. For example, your application may need
121
+ to append the current date to all its web assets in order to bust the cache
122
+ every day::
122
123
123
124
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
124
125
@@ -178,10 +179,10 @@ context of the current request::
178
179
echo $package->getUrl('/logo.png');
179
180
// result: /somewhere/static/images/logo.png?v1
180
181
181
- When the request context is set (via the third optional argument), in addition
182
- to the configured base path, ``PathPackage `` also prepends the current request
183
- base URL (``/somewhere/ `` in this example) to assets. This allows your website
184
- to be hosted anywhere under the web server root directory.
182
+ When the request context is set (via an optional third argument), in addition to
183
+ the configured base path, ``PathPackage `` also prepends the current request base
184
+ URL (``/somewhere/ `` in this example) to assets. This allows your website to be
185
+ hosted anywhere under the web server root directory.
185
186
186
187
Absolute Assets and CDNs
187
188
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -247,7 +248,7 @@ Named Packages
247
248
248
249
Applications that manage lots of different assets may need to group them in
249
250
packages with the same versioning strategy and base path. The Asset component
250
- includes a :class: `Symfony\\ Component\\ Asset\\ Packages ` class to simplify the
251
+ includes a :class: `Symfony\\ Component\\ Asset\\ Packages ` class to simplify
251
252
management of several packages.
252
253
253
254
In the following example, all packages use the same versioning strategy, but
0 commit comments