@@ -59,13 +59,23 @@ correct prioritization and the content security policy:
5959
6060    <head>
6161        <!-- ... -->
62-         <link rel="preload" href="{{ preload('/app.css', { as: 'style' }) }}">
62+         {# note that you must add two <link> tags per asset:
63+            one to link to it and the other one to tell the browser to preload it #}
64+         <link rel="preload" href="{{ preload('/app.css', {as: 'style'}) }}" as="style">
65+         <link rel="stylesheet" href="/app.css">
6366    </head>
6467
6568If you reload the page, the perceived performance will improve because the
6669server responded with both the HTML page and the CSS file when the browser only
6770requested the HTML page.
6871
72+ .. tip ::
73+ 
74+     When using the :doc: `AssetMapper component  </frontend/asset_mapper >` to link
75+     to assets (e.g. ``importmap('app') ``), there's no need to add the ``<link rel="preload"> ``
76+     tag. The ``importmap() `` Twig function automatically adds the ``Link `` HTTP
77+     header for you when the WebLink component is available.
78+ 
6979.. note ::
7080
7181    You can preload an asset by wrapping it with the ``preload() `` function:
@@ -74,7 +84,8 @@ requested the HTML page.
7484
7585        <head>
7686            <!-- ... -->
77-             <link rel="preload" href="{{ preload(asset('build/app.css')) }}">
87+             <link rel="preload" href="{{ preload(asset('build/app.css')) }}" as="style">
88+             <!-- ... -->
7889        </head>
7990
8091Additionally, according to `the Priority Hints specification `_, you can signal
@@ -84,7 +95,8 @@ the priority of the resource to download using the ``importance`` attribute:
8495
8596    <head>
8697        <!-- ... -->
87-         <link rel="preload" href="{{ preload('/app.css', { as: 'style', importance: 'low' }) }}">
98+         <link rel="preload" href="{{ preload('/app.css', {as: 'style', importance: 'low'}) }}" as="style">
99+         <!-- ... -->
88100    </head>
89101
90102How does it work?
@@ -108,7 +120,8 @@ issuing an early separate HTTP request, use the ``nopush`` option:
108120
109121    <head>
110122        <!-- ... -->
111-         <link rel="preload" href="{{ preload('/app.css', { as: 'style', nopush: true }) }}">
123+         <link rel="preload" href="{{ preload('/app.css', {as: 'style', nopush: true}) }}" as="style">
124+         <!-- ... -->
112125    </head>
113126
114127Resource Hints
@@ -142,7 +155,8 @@ any link implementing the `PSR-13`_ standard. For instance, any
142155    <head>
143156        <!-- ... -->
144157        <link rel="alternate" href="{{ link('/index.jsonld', 'alternate') }}">
145-         <link rel="preload" href="{{ preload('/app.css', { as: 'style', nopush: true }) }}">
158+         <link rel="preload" href="{{ preload('/app.css', {as: 'style', nopush: true}) }}" as="style">
159+         <!-- ... -->
146160    </head>
147161
148162The previous snippet will result in this HTTP header being sent to the client:
0 commit comments