Skip to content

FlashcardNot attempted

modulepreload

Recall it before you reveal

What problem does <link rel="modulepreload" href="/assets/Checkout-x1.js"> solve?

Space to reveal
Show answer & explanation

Without it, chunks load in a waterfall: download the entry → run it → discover import('./Checkout-x1.js') → download that → discover its imports → download those.

modulepreload tells the browser up front to fetch (and parse) a module, so chunks the page will certainly need download in parallel with the entry. Vite adds these links for the entry's static imports, and its preload helper fetches a lazy chunk's dependencies together with it. A prerendered page can also list its own route's chunks in its HTML.

Use it for what the page needs now; for the *next* likely route, prefetch when idle or on hover instead.