Skip to content

Commit

Permalink
Update disabling-http-keep-alive.md for server-side only (#43374)
Browse files Browse the repository at this point in the history
fixes #43354

It is not possible to specify an `agent` on a single `fetch()` call since the types for `fetch` come from TypeScript where `agent` is not supported as an option.
  • Loading branch information
longzheng committed Dec 19, 2022
1 parent 9855fd7 commit 2f79baf
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions docs/api-reference/next.config.js/disabling-http-keep-alive.md
Expand Up @@ -4,19 +4,9 @@ description: Next.js will automatically use HTTP Keep-Alive by default. Learn mo

# Disabling HTTP Keep-Alive

Next.js automatically polyfills [node-fetch](/docs/basic-features/supported-browsers-features#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default. You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally.
In Node.js versions prior to 18, Next.js automatically polyfills `fetch()` with [node-fetch](/docs/basic-features/supported-browsers-features#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default.

For a single `fetch()` call, you can add the agent option:

```js
import { Agent } from 'https'

const url = 'https://example.com'
const agent = new Agent({ keepAlive: false })
fetch(url, { agent })
```

To override all `fetch()` calls globally, you can use `next.config.js`:
To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config:

```js
module.exports = {
Expand Down

0 comments on commit 2f79baf

Please sign in to comment.