@@ -183,18 +183,24 @@ You can also add links to the HTTP response directly from controllers and servic
183
183
public function index(Request $request): Response
184
184
{
185
185
// using the addLink() shortcut provided by AbstractController
186
- $this->addLink($request, (new Link(Link::REL_PRELOAD , '/app.css'))->withAttribute('as', 'style'));
186
+ $this->addLink($request, (new Link('preload' , '/app.css'))->withAttribute('as', 'style'));
187
187
188
188
// alternative if you don't want to use the addLink() shortcut
189
189
$linkProvider = $request->attributes->get('_links', new GenericLinkProvider());
190
190
$request->attributes->set('_links', $linkProvider->withLink(
191
- (new Link(Link::REL_PRELOAD , '/app.css'))->withAttribute('as', 'style')
191
+ (new Link('preload' , '/app.css'))->withAttribute('as', 'style')
192
192
));
193
193
194
194
return $this->render('...');
195
195
}
196
196
}
197
197
198
+ .. tip ::
199
+
200
+ The possible values of link relations (``'preload' ``, ``'preconnect' ``, etc.)
201
+ are also defined as constants in the :class: `Symfony\\ Component\\ WebLink\\ Link `
202
+ class (e.g. ``Link::REL_PRELOAD ``, ``Link::REL_PRECONNECT ``, etc.).
203
+
198
204
.. _`WebLink` : https://github.com/symfony/web-link
199
205
.. _`HTTP/2 Server Push` : https://tools.ietf.org/html/rfc7540#section-8.2
200
206
.. _`Resource Hints` : https://www.w3.org/TR/resource-hints/
0 commit comments