From c275baf7f5e03a517358e5751304412e2a5b3fcc Mon Sep 17 00:00:00 2001 From: Tristan Bessoussa Date: Tue, 28 May 2019 14:35:59 +0200 Subject: [PATCH 1/2] 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: ``` must have a valid `as` value` ``` --- web_link.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/web_link.rst b/web_link.rst index 8d626733344..f37ce8e7cf0 100644 --- a/web_link.rst +++ b/web_link.rst @@ -61,7 +61,7 @@ WebLink: - + 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: - + .. tip:: @@ -88,8 +88,7 @@ How does it work? The WebLink component manages the ``Link`` HTTP headers added to the response. When using the ``preload()`` function in the previous example, the following -header was added to the response: ``Link ; rel="preload"`` - +header was added to the response: ``Link ; rel="preload; as="style""`` According to `the Preload specification`_, when an HTTP/2 server detects that the original (HTTP 1.x) response contains this HTTP header, it will 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: - + Resource Hints @@ -139,7 +138,7 @@ any link implementing the `PSR-13`_ standard. For instance, any - + The previous snippet will result in this HTTP header being sent to the client: @@ -164,7 +163,7 @@ You can also add links to the HTTP response directly from controllers and servic // alternative if you don't want to use the addLink() shortcut $linkProvider = $request->attributes->get('_links', new GenericLinkProvider()); - $request->attributes->set('_links', $linkProvider->withLink(new Link('preload', '/app.css'))); + $request->attributes->set('_links', $linkProvider->withLink(new Link('preload', '/app.css', ['as' : 'style']))); return $this->render('...'); } From 8e65d07c38e1a4ac885f9212cec37efb40b5081f Mon Sep 17 00:00:00 2001 From: Tristan Bessoussa Date: Tue, 28 May 2019 14:38:17 +0200 Subject: [PATCH 2/2] fix wrong quotes --- web_link.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_link.rst b/web_link.rst index f37ce8e7cf0..35eab37db51 100644 --- a/web_link.rst +++ b/web_link.rst @@ -88,7 +88,7 @@ How does it work? The WebLink component manages the ``Link`` HTTP headers added to the response. When using the ``preload()`` function in the previous example, the following -header was added to the response: ``Link ; rel="preload; as="style""`` +header was added to the response: ``Link ; rel="preload"; as="style"`` According to `the Preload specification`_, when an HTTP/2 server detects that the original (HTTP 1.x) response contains this HTTP header, it will automatically trigger a push for the related file in the same HTTP/2 connection.