[]previous and next page

preinitModule

Loads and runs an ES module now (React's preinitModule).

Loads and runs an ES module now (React's preinitModule). On the client it inserts a <script type="module">; on the server it hints the module with modulepreload, since the script itself is loaded by the page.

Import#

ts
import { preinitModule } from "@shadow-js/web";

Signature#

ts
function preinitModule(href: string, options?: CrossOriginOptions): void

Parameters#

Name Description
href An http(s) or relative URL of the module.
options CORS mode. Undefined adds no crossorigin attribute.

Throws#

  • TypeError (production message SHADOW_RESOURCE_HINT_URL) for a URL that is not http(s) or relative.

Examples#

ts
import { preinitModule } from "@shadow-js/web";

preinitModule("/chunks/app.js");