123movies-seo/app/Http/Middleware/AddLinkHeadersForPreloadedFonts.php

26 lines
704 B
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Support\Collection;
class AddLinkHeadersForPreloadedFonts
{
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response
*/
public function handle($request, $next)
{
return tap($next($request), function ($response) {
if (config('fonts') !== []) {
$response->header('Link', Collection::make(config('fonts'))
->map(fn ($url) => "<{$url}>; " . 'rel="preload"; as=font; type="font/woff2"; crossorigin')
->join(', '));
}
});
}
}