mirror of
https://github.com/symfony/symfony-docs.git
synced 2026-03-23 16:22:10 +01:00
Minor tweaks
This commit is contained in:
10
web_link.rst
10
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/
|
||||
|
||||
Reference in New Issue
Block a user