The WebLink Component
The WebLink component provides tools to manage theLink
HTTP header neededfor Web Linking when using HTTP/2 Server Push as well as Resource Hints.
Installation
- $ composer require symfony/web-link
Note
If you install this component outside of a Symfony application, you mustrequire the vendor/autoload.php
file in your code to enable the classautoloading mechanism provided by Composer. Readthis article for more details.
Usage
The following example shows the component in action:
- use Fig\Link\GenericLinkProvider;
- use Fig\Link\Link;
- use Symfony\Component\WebLink\HttpHeaderSerializer;
- $linkProvider = (new GenericLinkProvider())
- ->withLink(new Link('preload', '/bootstrap.min.css'));
- header('Link: '.(new HttpHeaderSerializer())->serialize($linkProvider->getLinks()));
- echo 'Hello';
Read the full WebLink documentation to learn about all thefeatures of the component and its integration with the Symfony framework.