Minor tweaks

This commit is contained in:
Javier Eguiluz
2025-07-10 09:30:09 +02:00
parent 393880a85a
commit abc8d6964a

View File

@@ -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/