HTML Tools

Modulepreload Tag Generator

Build rel='modulepreload' link tags with the correct crossorigin attribute. Designed for modern JavaScript module workflows in Vite, Astro, SvelteKit, and vanilla ES module projects.

Loading tool...

What is Modulepreload Tag Generator?

Modulepreload is a specialized preload for ES module scripts. Unlike standard preload, modulepreload understands module dependency graphs. It is commonly used in Vite and Astro output. It needs the correct crossorigin attribute for cross-origin modules.

Quick answer

Use modulepreload to speculatively fetch, parse, and compile ES module dependencies before they are needed. It works like preload but is designed specifically for JavaScript module scripts.

Limitations

  • modulepreload is only effective for ES module scripts (type='module'). It does not apply to classic scripts.
  • Browser support lags behind standard preload. Firefox added support in 115+, Safari in 17.2+.
  • modulepreload fetches the module but does not execute it. Execution still happens when the module script tag is encountered.

How to use this tool

  1. Enter the module script path or URL.
  2. Choose whether the module is same-origin or cross-origin.
  3. The tool adds the correct crossorigin attribute for the selected origin type.
  4. Copy the tag into the page head before other module scripts.

What you can use it for

  • Add modulepreload for a Vite-built JavaScript entry module.
  • Preload a shared ES module chunk for faster page transitions.
  • Optimize module loading on a static site built with Astro or SvelteKit.

Use cases

Practical examples

Example

Vite vendor chunk preloading

A Vite project outputs a vendor chunk that multiple pages use. Modulepreload fetches it early so navigation between pages feels instant.

Example

Astro site with CDN-hosted modules

A static site built with Astro uses modulepreload for the main entry script with crossorigin for CDN hosting.

Common mistakes

  • Using standard preload instead of modulepreload for ES modules.
  • Forgetting crossorigin on cross-origin module URLs.
  • Adding modulepreload for non-module scripts.

Verification

  1. Open Chrome DevTools Network panel and verify module scripts fetched via modulepreload appear early in the waterfall.
  2. Check the Coverage panel to confirm the module is being used and not fetched unnecessarily.

FAQ

Questions about Modulepreload Tag Generator

Can I use modulepreload for non-module scripts?

No. Use standard preload for regular scripts. Modulepreload is specifically designed for ES module dependency graphs.

Which browsers support modulepreload?

Chrome 66+, Edge 79+, Firefox 115+, Safari 17.2+. It is safe as a progressive enhancement.

Related tools

More html tools

Also try

Also try