8000 Merge branch '7.3' into 7.4 · symfony/symfony-docs@a7c895b · GitHub
[go: up one dir, main page]

Skip to content

Commit a7c895b

Browse files
committed
Merge branch '7.3' into 7.4
* 7.3: Reword [Templating] Adding AssetMapper to `asset()` function
2 parents 742ecdd + d108ae2 commit a7c895b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

reference/configuration/framework.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ file_cache_dir
5757
The directory to store cache files for annotations, in case
5858
``annotations.cache`` is set to ``'file'``.
5959

60+
.. _reference-assets:
61+
6062
assets
6163
~~~~~~
6264

templates.rst

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,18 @@ You can now use the ``asset()`` function:
312312
{# the JS file lives at "public/bundles/acme/js/loader.js" #}
313313
<script src="{{ asset('bundles/acme/js/loader.js') }}"></script>
314314

315-
The ``asset()`` function's main purpose is to make your application more portable.
316-
If your application lives at the root of your host (e.g. ``https://example.com``),
317-
then the rendered path should be ``/images/logo.png``. But if your application
318-
lives in a subdirectory (e.g. ``https://example.com/my_app``), each asset path
319-
should render with the subdirectory (e.g. ``/my_app/images/logo.png``). The
320-
``asset()`` function takes care of this by determining how your application is
321-
being used and generating the correct paths accordingly.
322-
323-
.. tip::
324-
325-
The ``asset()`` function supports various cache busting techniques via the
326-
:ref:`version <reference-framework-assets-version>`,
327-
:ref:`version_format <reference-assets-version-format>`, and
328-
:ref:`json_manifest_path <reference-assets-json-manifest-path>` configuration options.
315+
Using the ``asset()`` function is recommended for these reasons:
316+
317+
* **Asset versioning**: ``asset()`` appends a version hash to asset URLs for
318+
cache busting. This works both via :doc:`AssetMapper </frontend>` and the
319+
:doc:`Asset component </components/asset>` (see also the
320+
:ref:`assets configuration options <reference-assets>`, such as ``version``
321+
and ``version_format``).
322+
323+
* **Application portability**: whether your app is hosted at the root
324+
(e.g. ``https://example.com``) or in a subdirectory (e.g. ``https://example.com/my_app``),
325+
``asset()`` generates the correct path (e.g. ``/images/logo.png`` vs ``/my_app/images/logo.png``)
326+
automatically based on your app's base URL.
329327

330328
If you need absolute URLs for assets, use the ``absolute_url()`` Twig function
331329
as follows:

0 commit comments

Comments
 (0)
0