-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
Laravel Version
11.30.0
PHP Version
8.3
Database Driver & Version
No response
Description
CORS (the crossorigin parameter) is required when dealing with scripts of type="module" or rel="modulepreload"
whatwg/html#1888
Thus adding these links as headers will prove ineffective both in Http/2 ServerPush and Http/3 Early Hints.
We might want to default the crossorigin parameter to anonymous to ensure preloading will always be effective.
framework/src/Illuminate/Foundation/Vite.php
Line 698 in ca0617a
| 'crossorigin' => $this->resolveScriptTagAttributes($src, $url, $chunk, $manifest)['crossorigin'] ?? false, |
Steps To Reproduce
Set up your regular laravel project, run yarn && yarn run build
add the link elements to the link header.
In a clean Laravel installation update your web.php to reflect
return response(view('welcome'))->header('Link', '<http://laravel.test/build/assets/app-<your hash>.js>; as=script; rel=preload');See the console warning in your browser claiming the preload has not been used due to incompatible crossorigin between your link headers and your script.

Also note in the network tab how the script is downloaded twice.

First during the preload, but since that is thrown away. The second time because it finds the script in your html.