# prefetchDNS()

> The `prefetchDNS()` API in React DOM eagerly looks up the IP address of a server.

## What does prefetchDNS do in React?

The API that resolves the domain name of an origin in advance, which saves time when resources from it are requested later. Equivalent to `<link rel="dns-prefetch">`.

- Topic: APIs [React DOM]
- Type: API

## Example

Wrong:

```jsx
function App() {
  preconnect('https://cdn.example.com');
  preconnect('https://maps.example.com');
  preconnect('https://chat.example.com');
  return <Page />;
}
```

Right:

```jsx
function App() {
  preconnect('https://cdn.example.com');
  prefetchDNS('https://maps.example.com');
  prefetchDNS('https://chat.example.com');
  return <Page />;
}
```

Only the origin needed right away gets a full connection; the others just resolve DNS, which costs far less.

## Common mistakes

- Calling it for the page's own origin, where DNS is already resolved.

## Key points

- `prefetchDNS` is imported from 'react-dom' and receives only a URL of another origin.
- Origins that will surely be used soon use `preconnect` instead, which also opens the connection.

## Interview questions

### Does prefetchDNS work during server rendering?

Yes. During server rendering React adds a dns-prefetch link to the HTML head, and on the client it inserts the tag.

### Can I call prefetchDNS in an event handler?

Yes. Calling it in a handler, such as on hover before a navigation, starts the lookup before the request is made.

## Related cards

- [\[rel="dns-prefetch"\]](https://wonderium.dev/html/rel-dns-prefetch.md)
- [preconnect()](https://wonderium.dev/react/preconnect.md)
- [preload()](https://wonderium.dev/react/preload.md)
- [DNS](https://wonderium.dev/web/dns.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/prefetch-dns
- Last updated: 2026-11-25
