preinit
Loads a stylesheet or script now, and keeps it applied or executed (React's preinit).
Loads a stylesheet or script now, and keeps it applied or executed (React's preinit). A
stylesheet becomes a <link rel="stylesheet">; a script becomes an async <script> in the head.
On the server a script can only be hinted as a preload, because head tags cannot be scripts.
Import#
ts
import { preinit } from "@shadow-js/web";
Signature#
ts
function preinit(href: string, options: PreinitOptions): void
Parameters#
| Name | Description |
|---|---|
href |
An http(s) or relative URL. |
options |
What to load (style or script, required) and the CORS mode. |
Throws#
- TypeError (production message
SHADOW_RESOURCE_HINT_URL) for a URL that is not http(s) or relative.
Examples#
ts
import { preinit } from "@shadow-js/web";
preinit("/theme.css", { as: "style" });