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

32 lines
1,002 B
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Support\Collection;
class AddPreconnectLink
{
/**
* 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('preconnect') !== []) {
$response->header('Link', Collection::make(config('preconnect'))
// ->map(fn ($url) => "<{$url}>; " . 'rel="preload"; as=font; type="font/woff2"; crossorigin')
->map(fn ($url) => "<{$url}>; " . 'rel="preconnect"')
->join(', ')
.', <https://code.jquery.com/jquery-3.3.1.min.js>;rel="preload";as="script";crossorigin;nopush'
,
false
);
}
});
}
}
https://code.jquery.com/jquery-3.3.1.min.js