preloadModule – React
preloadModule – React
v19
preloadModule
Note
Reference
preloadModule(href, options)
Usage
Reference
preloadModule(href, options)
https://react.dev/reference/react-dom/preloadModule 1/5
20/02/2025, 19:12 preloadModule – React
function AppRoot() {
preloadModule("https://example.com/module.js", {as: "script"});
// ...
}
The preloadModule function provides the browser with a hint that it should
start downloading the given module, which can save time.
Parameters
crossOrigin : a string. The CORS policy to use. Its possible values are
anonymous and use-credentials .
Returns
Caveats
Multiple calls to preloadModule with the same href have the same
effect as a single call.
In the browser, you can call preloadModule in any situation: while
rendering a component, in an Effect, in an event handler, and so on.
https://react.dev/reference/react-dom/preloadModule 2/5
20/02/2025, 19:12 preloadModule – React
Usage
function AppRoot() {
preloadModule("https://example.com/module.js", {as: "script"});
return ...;
}
If you want the browser to start executing the module immediately (rather
than just downloading it), use preinitModule instead. If you want to load a
script that isn’t an ESM module, use preload .
function CallToAction() {
const onClick = () => {
preloadModule("https://example.com/module.js", {as: "script"});
startWizard();
https://react.dev/reference/react-dom/preloadModule 3/5
20/02/2025, 19:12 preloadModule – React
}
return (
<button onClick={onClick}>Start Wizard</button>
);
}
PREVIOUS
preload
NEXT
Client APIs
uwu?
Describing the UI
Adding Interactivity
Managing State
Escape Hatches
Community More
https://react.dev/reference/react-dom/preloadModule 4/5
20/02/2025, 19:12 preloadModule – React
Acknowledgements Terms
https://react.dev/reference/react-dom/preloadModule 5/5