[]previous and next page

preconnect

Tells the browser to open a connection (DNS, TCP, TLS) to an origin the page will use soon.

Tells the browser to open a connection (DNS, TCP, TLS) to an origin the page will use soon. React's preconnect. Calling it again for the same origin adds nothing. Works in a component, in an event handler, or at module scope on the client.

Import#

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

Signature#

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

Parameters#

Name Description
href An http(s) origin or URL.
options CORS mode (needed for fonts and fetch with credentials). 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 { preconnect } from "@shadow-js/web";

preconnect("https://fonts.example.com", { crossOrigin: "anonymous" });