symfony/web-link
Symfony WebLink component helps manage link relationships between resources. Create and serialize HTTP Link headers for preload, prefetch, and resource hints (HTML5/Web standards), enabling better performance via HTTP/2 push and client hints.
Link headers, ensuring compatibility with modern browsers, CDNs, and HTTP/2 servers. This aligns perfectly with Laravel’s emphasis on performance and interoperability.Link headers based on routes, user segments, or asset types (e.g., preload CSS for /dashboard).LinkManager::getPreloadLinksForRoute()).Response objects, allowing headers to be added via:
header('Link: ...') in controllers/middleware.withHeaders() in responses.Macro methods for Response class.@preload) to embed link headers in templates or generate <link> tags for HTML responses.LinkHeaderParser to parse Link headers from external APIs (e.g., for HATEOAS or pagination).rel="stylesheet" with untrusted URLs) could lead to XSS or resource hijacking.
Mitigation: Validate link attributes (e.g., href domains, rel types) via middleware or a whitelist.Link headers could impact client parsing.
Mitigation: Limit header size or number of links per response.symfony/http-client bridge.HttpTests or BrowserKit).proxy_ssl_server_name, Apache mod_http2). Not all hosts support this./dashboard) or dynamic (e.g., generated per user session or API response)?href domains (e.g., allow only CDN or same-origin)?Response class or create a facade for easier usage?Link headers on performance (e.g., TTI, LCP)?Link headers are stripped (e.g., legacy proxies)?HttpClient, HttpFoundation) used in Laravel via bridges like symfony/http-client.Link headers (e.g., Cloudflare’s Link header support). May require configuration for legacy proxies.composer require symfony/web-link.Link headers (e.g., preload /css/main.css)./home, /product).manifest, apple-touch-icon) or APIs (HATEOAS).web-link versions), but not recommended due to EOL risks.symfony/http-foundation).WebLinkServiceProvider).GenericLinkProvider and HttpHeaderSerializer to the container.AddPreloadHeaders) to inject headers into responses.public function handle($request, Closure $next) {
$response = $next($request);
$linkProvider = app(GenericLinkProvider::class)
->withLink(new Link('preload', '/css/main.css', ['as' => 'style']));
$response->headers->set('Link', (new HttpHeaderSerializer())->serialize($linkProvider->getLinks()));
return $response;
}
How can I help you explore Laravel packages today?