The WebLink Component

The WebLink component provides tools to manage the Link HTTP header neededfor Web Linking when using HTTP/2 Server Push as well as Resource Hints.

Installation

  1. $ 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:

  1. use Fig\Link\GenericLinkProvider;
  2. use Fig\Link\Link;
  3. use Symfony\Component\WebLink\HttpHeaderSerializer;
  4.  
  5. $linkProvider = (new GenericLinkProvider())
  6. ->withLink(new Link('preload', '/bootstrap.min.css'));
  7.  
  8. header('Link: '.(new HttpHeaderSerializer())->serialize($linkProvider->getLinks()));
  9.  
  10. echo 'Hello';

Read the full WebLink documentation to learn about all thefeatures of the component and its integration with the Symfony framework.