Link
modulepreload
Fetches a JavaScript module early and stores it in the document's module map. Browsers may also fetch its dependencies.
Code examples
Good example
<link rel="modulepreload" href="/scripts/app.mjs">Fetches a module before a later module script or import needs it.
Avoid this example
<link rel="modulepreload" href="/scripts/app.mjs" as="style">Uses a non-script destination, so the link does not meet the modulepreload requirements.
Recommendations
- 01Preload only important modulesUse it when late discovery would add a meaningful delay. Preloading a large module graph can compete with resources needed for rendering.
- 02Configure cross-origin modulesModule fetches use CORS. A cross-origin server must return the required CORS headers, while crossorigin controls the credentials mode.
- 03Keep as script-likeOmit as or use a script-like destination. Values such as style make the modulepreload link invalid.