The WebLink Component

Version: 4.3
Edit this page

Warning: You are browsing the documentation for Symfony 4.3, which is no longer maintained.

Read the updated version of this page for Symfony 6.0 (the current stable version).

The WebLink Component

The WebLink component provides tools to manage the Link HTTP header needed for 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 must require the vendor/autoload.php file in your code to enable the class autoloading mechanism provided by Composer. Read this article for more details.

Usage

The following example shows the component in action:

1
2
3
4
5
6
7
8
9
10
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 the features of the component and its integration with the Symfony framework.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.