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 with Laravel’s emphasis on interoperability and performance.Link headers dynamically (e.g., per route or user segment).LinkProvider as a singleton for centralized management.withHeaders() or middleware.// app/Http/Middleware/InjectWebLinks.php
public function handle(Request $request, Closure $next) {
$response = $next($request);
$links = (new GenericLinkProvider())
->withLink(new Link('preload', asset('app.css'), ['as' => 'style']));
return $response->header('Link', (new HttpHeaderSerializer())->serialize($links));
}
GET requests or specific routes).Response objects, enabling header injection in controllers, API resources, or event listeners.<link rel="preload"> in HTML).rel="stylesheet" pointing to untrusted domains) could expose users to XSS or data leaks.rel values (e.g., ['preload', 'prefetch', 'dns-prefetch']).href attributes against allowed domains (e.g., via Laravel’s ValidatesWhen or custom validator).proxy_ssl_server_name).Link headers. Test with Can I Use and BrowserStack.@supports (link: preload) in CSS) for fallback strategies.^7.4) and set up dependency alerts.HttpTests trait or tools like Symfony’s WebTestCase.rel values and href domains are allowed? How will we validate them?proxy_ssl_server_name).<link rel="preload"> in Blade).app.css, main.js).
// app/Http/Middleware/PreloadCriticalAssets.php
public function handle($request, Closure $next) {
$response = $next($request);
$links = (new GenericLinkProvider())
->withLink(new Link('preload', asset('css/app.css'), ['as' => 'style']))
->withLink(new Link('preload', asset('js/app.js'), ['as' => 'script']));
return $response->header('Link', (new HttpHeaderSerializer())->serialize($links));
}
config('weblink.enabled')).as attributes).rel="modulepreload").How can I help you explore Laravel packages today?