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.
<link rel="modulepreload">
Baseline 2023 newly available
Supported in Chrome: yes.
Supported in Edge: yes.
Supported in Firefox: yes.
Supported in Safari: yes.
Since September 2023 this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
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.
The real power comes when dealing with module dependencies. A single modulepreload handles the entire dependency graph automatically. When your main module imports other modules, modulepreload fetches and prepares them all - no need for separate hints.
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.