loadScript
Loads a script in the browser (the lazyOnload strategy: call it after the window's load event).
Loads a script in the browser (the lazyOnload strategy: call it after the window's load event). Resolves
when the script has run and rejects when it fails to load. A source already loaded resolves at once.
Import#
ts
import { loadScript } from "@shadow-js/dusk/client";
Signature#
ts
function loadScript(options: LoadScriptOptions): Promise<void>
Parameters#
| Name | Description |
|---|---|
options |
The source, nonce and document. |
Returns#
A promise for the load.
Throws#
- TypeError for a source that is not a path or an http(s) URL.
Examples#
ts
window.addEventListener("load", () => void loadScript({ src: "/chat-widget.js" }));