diff --git a/web_link.rst b/web_link.rst index 72d22c50b6..2f2f96d106 100644 --- a/web_link.rst +++ b/web_link.rst @@ -183,18 +183,24 @@ You can also add links to the HTTP response directly from controllers and servic public function index(Request $request): Response { // using the addLink() shortcut provided by AbstractController - $this->addLink($request, (new Link(Link::REL_PRELOAD, '/app.css'))->withAttribute('as', 'style')); + $this->addLink($request, (new Link('preload', '/app.css'))->withAttribute('as', 'style')); // 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(Link::REL_PRELOAD, '/app.css'))->withAttribute('as', 'style') + (new Link('preload', '/app.css'))->withAttribute('as', 'style') )); return $this->render('...'); } } +.. tip:: + + The possible values of link relations (``'preload'``, ``'preconnect'``, etc.) + are also defined as constants in the :class:`Symfony\\Component\\WebLink\\Link` + class (e.g. ``Link::REL_PRELOAD``, ``Link::REL_PRECONNECT``, etc.). + .. _`WebLink`: https://github.com/symfony/web-link .. _`HTTP/2 Server Push`: https://tools.ietf.org/html/rfc7540#section-8.2 .. _`Resource Hints`: https://www.w3.org/TR/resource-hints/