@@ -61,7 +61,7 @@ WebLink:
61
61
62
62
<head>
63
63
<!-- ... -->
64
- <link rel="stylesheet" href="{{ preload('/app.css') }}">
64
+ <link rel="stylesheet" href="{{ preload('/app.css', { as: 'style' } ) }}">
65
65
</head>
66
66
67
67
If you reload the page, the perceived performance will improve because the
@@ -75,7 +75,7 @@ the priority of the resource to download using the ``importance`` attribute:
75
75
76
76
<head>
77
77
<!-- ... -->
78
- <link rel="stylesheet" href="{{ preload('/app.css', { importance: 'low' }) }}">
78
+ <link rel="stylesheet" href="{{ preload('/app.css', { as: 'style', importance: 'low' }) }}">
79
79
</head>
80
80
81
81
.. tip ::
@@ -88,8 +88,7 @@ How does it work?
88
88
89
89
The WebLink component manages the ``Link `` HTTP headers added to the response.
90
90
When using the ``preload() `` function in the previous example, the following
91
- header was added to the response: ``Link </app.css>; rel="preload" ``
92
-
91
+ header was added to the response: ``Link </app.css>; rel="preload"; as="style" ``
93
92
According to `the Preload specification `_, when an HTTP/2 server detects that
94
93
the original (HTTP 1.x) response contains this HTTP header, it will
95
94
automatically trigger a push for the related file in the same HTTP/2 connection.
@@ -105,7 +104,7 @@ issuing an early separate HTTP request, use the ``nopush`` option:
105
104
106
105
<head>
107
106
<!-- ... -->
108
- <link rel="stylesheet" href="{{ preload('/app.css', { nopush: true }) }}">
107
+ <link rel="stylesheet" href="{{ preload('/app.css', { as: 'style', nopush: true }) }}">
109
108
</head>
110
109
111
110
Resource Hints
@@ -139,7 +138,7 @@ any link implementing the `PSR-13`_ standard. For instance, any
139
138
<head>
140
139
<!-- ... -->
141
140
<link rel="alternate" href="{{ link('/index.jsonld', 'alternate') }}">
142
- <link rel="stylesheet" href="{{ preload('/app.css', { nopush: true }) }}">
141
+ <link rel="stylesheet" href="{{ preload('/app.css', { as: 'style', nopush: true }) }}">
143
142
</head>
144
143
145
144
The previous snippet will result in this HTTP header being sent to the client:
@@ -160,7 +159,7 @@ You can also add links to the HTTP response directly from controllers and servic
160
159
public function index(Request $request)
161
160
{
162
161
$linkProvider = $request->attributes->get('_links', new GenericLinkProvider());
163
- $request->attributes->set('_links', $linkProvider->withLink(new Link('preload', '/app.css')));
162
+ $request->attributes->set('_links', $linkProvider->withLink(new Link('preload', '/app.css', ['as' : 'style'] )));
164
163
165
164
return $this->render('...');
166
165
}
0 commit comments