preinitModule – React
preinitModule – React
v19
preinitModule
Note
Reference
preinitModule(href, options)
Usage
Reference
preinitModule(href, options)
https://react.dev/reference/react-dom/preinitModule 1/5
20/02/2025, 19:12 preinitModule – React
function AppRoot() {
preinitModule("https://example.com/module.js", {as: "script"});
// ...
}
The preinitModule function provides the browser with a hint that it should
start downloading and executing the given module, which can save time.
Modules that you preinit are executed when they finish downloading.
Parameters
href : a string. The URL of the module you want to download and
execute.
options : an object. It contains the following properties:
crossOrigin : a string. The CORS policy to use. Its possible values are
anonymous and use-credentials .
Returns
Caveats
Multiple calls to preinitModule with the same href have the same
effect as a single call.
https://react.dev/reference/react-dom/preinitModule 2/5
20/02/2025, 19:12 preinitModule – React
Usage
function AppRoot() {
preinitModule("https://example.com/module.js", {as: "script"});
return ...;
}
If you want the browser to download the module but not to execute it right
away, use preloadModule instead. If you want to preinit a script that isn’t an
ESM module, use preinit .
https://react.dev/reference/react-dom/preinitModule 3/5
20/02/2025, 19:12 preinitModule – React
function CallToAction() {
const onClick = () => {
preinitModule("https://example.com/module.js", {as: "script"});
startWizard();
}
return (
<button onClick={onClick}>Start Wizard</button>
);
}
PREVIOUS
preinit
NEXT
preload
uwu?
Describing the UI
Adding Interactivity
Managing State
Escape Hatches
Community More
https://react.dev/reference/react-dom/preinitModule 4/5
20/02/2025, 19:12 preinitModule – React
Acknowledgements Terms
https://react.dev/reference/react-dom/preinitModule 5/5