Skip to content

Commit 5df84ca

Browse files
committed
minor #11615 [WebLink] All mentions to preload must have an "as" attribute (tristanbes)
This PR was submitted for the master branch but it was squashed and merged into the 3.4 branch instead (closes #11615). Discussion ---------- [WebLink] All mentions to preload must have an "as" attribute All the examples mentionning a `preload` must contain also a `'as' => 'xxx'` attribute. Otherwise, it generates a warning on the browser console: ``` ⚠️ <link rel=preload> must have a valid `as` value` ``` <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- a725141 [WebLink] All mentions to preload must have an \"as\" attribute
2 parents fbc4f07 + a725141 commit 5df84ca

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

web_link.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ WebLink:
6161

6262
<head>
6363
<!-- ... -->
64-
<link rel="stylesheet" href="{{ preload('/app.css') }}">
64+
<link rel="stylesheet" href="{{ preload('/app.css', { as: 'style' }) }}">
6565
</head>
6666

6767
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:
7575

7676
<head>
7777
<!-- ... -->
78-
<link rel="stylesheet" href="{{ preload('/app.css', { importance: 'low' }) }}">
78+
<link rel="stylesheet" href="{{ preload('/app.css', { as: 'style', importance: 'low' }) }}">
7979
</head>
8080

8181
.. tip::
@@ -88,8 +88,7 @@ How does it work?
8888

8989
The WebLink component manages the ``Link`` HTTP headers added to the response.
9090
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"``
9392
According to `the Preload specification`_, when an HTTP/2 server detects that
9493
the original (HTTP 1.x) response contains this HTTP header, it will
9594
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:
105104

106105
<head>
107106
<!-- ... -->
108-
<link rel="stylesheet" href="{{ preload('/app.css', { nopush: true }) }}">
107+
<link rel="stylesheet" href="{{ preload('/app.css', { as: 'style', nopush: true }) }}">
109108
</head>
110109

111110
Resource Hints
@@ -139,7 +138,7 @@ any link implementing the `PSR-13`_ standard. For instance, any
139138
<head>
140139
<!-- ... -->
141140
<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 }) }}">
143142
</head>
144143

145144
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
160159
public function index(Request $request)
161160
{
162161
$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'])));
164163

165164
return $this->render('...');
166165
}

0 commit comments

Comments
 (0)