---
title: "link rel=modulepreload: Load JavaScript Modules Sooner"
description: "rel=modulepreload fetches, parses and compiles an ES module before a script imports it. How to use it, and why each module in the graph needs its own link."
canonical: "https://www.trevorlasn.com/blog/module-preload"
author: "Trevor I. Lasn"
published: "2024-12-04"
last-updated: "2026-11-08"
topics: ["Web performance", "HTML", "JavaScript"]
---

# link rel=modulepreload: Load JavaScript Modules Sooner

rel=modulepreload fetches, parses and compiles an ES module before a script imports it. How to use it, and why each module in the graph needs its own link.

By Trevor I. Lasn · Published 2024-12-04 · Updated 2026-11-08 · https://www.trevorlasn.com/blog/module-preload

Web performance often comes down to smart resource loading. While we've had preload hints for a while, modulepreload is specifically designed for the way modern JavaScript works. Let's unpack what makes it special.

## Update: One modulepreload doesn't fetch the whole graph

I originally wrote that a single modulepreload fetches a module's entire dependency graph. It doesn't.

The HTML spec lets browsers fetch a preloaded module's dependencies only as an optional optimization. MDN says the only way to make every browser preload them is to list each module ([HTML spec](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload), [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/modulepreload)). I've fixed the paragraph and the example below.

[Browser support for `modulepreload` on webstatus.dev](https://webstatus.dev/features/modulepreload)

When you use `<link rel="modulepreload">`, you're telling the browser: "Hey, I'm going to need this module soon - could you fetch it and get it ready?" The browser then fetches the module, parses it, and compiles it ahead of time. This is different from regular preload, which only handles the fetching part.

```html title="HTML"
<!-- This only fetches the file -->
<link rel="preload" href="/js/app.js" as="script">

<!-- This fetches, parses, and compiles the module -->
<link rel="modulepreload" href="/js/app.js">
```

The real power comes when dealing with module dependencies. Without hints, the browser only finds out that `main.js` imports `utils.js` and `data.js` after it has fetched and parsed `main.js`, so the modules load one after another.

A modulepreload for each module lets the browser fetch them in parallel and put them straight into its module map. Browsers may also fetch a preloaded module's dependencies on their own, but that's optional, so list every module you need early.

```html title="HTML"
<!-- Before: Multiple preloads needed -->
<link rel="preload" href="/js/main.js" as="script">
<link rel="preload" href="/js/utils.js" as="script">
<link rel="preload" href="/js/data.js" as="script">

<!-- After: one modulepreload per module -->
<link rel="modulepreload" href="/js/main.js">
<link rel="modulepreload" href="/js/utils.js">
<link rel="modulepreload" href="/js/data.js">
```

<br />

### When to use `modulepreload`

`modulepreload` excels in applications with substantial JavaScript dependencies or route-based code splitting. But consider the memory trade-off - modulepreload compiles modules upfront, consuming more memory. For smaller apps or rarely-used modules, regular dynamic imports might be more efficient.
