@@ -312,20 +312,18 @@ You can now use the ``asset()`` function:
312
312
{# the JS file lives at "public/bundles/acme/js/loader.js" #}
313
313
<script src="{{ asset('bundles/acme/js/loader.js') }}"></script>
314
314
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.
329
327
330
328
If you need absolute URLs for assets, use the ``absolute_url() `` Twig function
331
329
as follows:
0 commit comments