Fprefetch
Bun

function

dns.prefetch

function prefetch(
hostname: string,
port?: number
): void;

Experimental API

Prefetch a hostname.

This will be used by fetch() and Bun.connect() to avoid DNS lookups.

@param hostname

The hostname to prefetch

@param port

The port to prefetch. Default is 443. Port helps distinguish between IPv6 vs IPv4-only connections.

import { dns } from 'bun';
dns.prefetch('example.com');
// ... something expensive
await fetch('https://example.com');