---
name: "up.network.config"
area: "API"
kind: "Configuration object"
parent: "up.network module"
url: "https://unpoly.com/api/up.network.config"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.network module](https://unpoly.com/api/up.network.md)</nav>

# up.network.config

Sets default options for network requests.

---

## Value {#value}

### Requests {#value-requests}

#### [config.concurrency] {#config.concurrency}

(optional)

The maximum number of concurrently loading requests.

Additional requests are queued. [Preload](https://unpoly.com/learn/preloading.md) requests are always queued behind non-preload requests.

By default Unpoly allows 6 concurrent requests. You might find it useful to set a concurrency of `1` in end-to-end tests to prevent race conditions.

Your browser may impose additional concurrency limits regardless of what you configure here.

Type: number | Function(): number

#### [config.wrapMethod=true] {#config.wrapMethod}

(optional)

Whether to wrap non-standard HTTP methods in a POST request.

If this is set, methods other than GET and POST will be converted to a `POST` request and will carry their original method as a `_method` parameter. This is to [prevent unexpected redirect behavior](https://makandracards.com/makandra/38347).

If you disable method wrapping, make sure that your server always redirects with a 303 status code (rather than 302).

Type: boolean

#### [config.lateDelay=400] {#config.lateDelay}

(optional)

The number of milliseconds to wait before emitting the [`up:network:late` event](https://unpoly.com/api/up:network:late.md) and showing the [progress bar](https://unpoly.com/learn/progress-bar.md).

To never consider a request to be late, configure a function that returns `false` for that request.

Type: number | Function([up.Request](https://unpoly.com/api/up.Request.md)): number | boolean

#### [config.timeout=90_000] {#config.timeout}

(optional)

A default [timeout](https://unpoly.com/api/up.request.md#options.timeout) for [requests](https://unpoly.com/api/up.request.md) in milliseconds.

Set `undefined` to not use a timeout.

Type: number | undefined

#### [config.fail] {#config.fail}

(optional)

Whether Unpoly will consider a response to constitute an [error response](https://unpoly.com/learn/error-responses.md).

By default, Unpoly will consider any status code other than HTTP 2xx or [304](https://unpoly.com/learn/conditional-requests.md#rendering-nothing) to represent an error response. You may use this option to customize this behavior. For instance, you can fail a response if it contains a given header or body text.

The following configuration will fail all responses with an `X-Unauthorized` header:

```js
let badStatus = up.network.config.fail
up.network.config.fail = (response) => badStatus(response) || response.header('X-Unauthorized')
```

Also see [Customizing failure detection](https://unpoly.com/learn/error-responses.md#customizing-failure-detection).

Type: boolean | Function([up.Response](https://unpoly.com/api/up.Response.md)): boolean

### Caching {#value-caching}

#### [config.cacheEnabled=true] {#config.cacheEnabled}

(optional)

Whether to use the [cache](https://unpoly.com/learn/caching.md).

When set to `false`, no response is read from or written to the cache, even for requests with `{ cache: true }`. [Preloading](https://unpoly.com/learn/preloading.md) is disabled as well.

See [Disabling the cache globally](https://unpoly.com/learn/caching.md#disabling-globally).

Type: boolean

#### [config.cacheSize=70] {#config.cacheSize}

(optional)

The maximum number of responses to cache.

If the size is exceeded, the oldest responses will be dropped from the cache.

Type: number

#### [config.cacheExpireAge=15_000] {#config.cacheExpireAge}

(optional)

The number of milliseconds after which a cache entry is considered [expired](https://unpoly.com/learn/caching.md#expiration) and will trigger [revalidation](https://unpoly.com/learn/caching.md#revalidation) when used.

The configured age should at least cover the average time between [preloading](https://unpoly.com/learn/preloading.md) and following a link.

Defaults to 15 seconds.

Type: number

#### [config.cacheEvictAge=90*60*1000] {#config.cacheEvictAge}

(optional)

The number of milliseconds after which a cache entry is [evicted](https://unpoly.com/learn/caching.md#eviction).

In practice you will often prefer [_expiration_](https://unpoly.com/learn/caching.md#expiration) over _eviction_.

Defaults to 90 minutes.

Type: number

#### [config.autoCache] {#config.autoCache}

(optional)

Whether to [cache](https://unpoly.com/learn/caching.md) the given request with `{ cache: 'auto' }`.

By default, Unpoly will auto-cache requests with [safe](https://developer.mozilla.org/en-US/docs/Glossary/Safe/HTTP) HTTP methods like `GET`.

You may change this default to prevent auto-caching of some of your routes. For example, this will prevent auto-caching of requests to URLs ending with `/edit`:

```js
let defaultAutoCache = up.network.config.autoCache
up.network.config.autoCache = function(request) {
  return defaultAutoCache(request) && !request.url.endsWith('/edit')
}
```

Type: Function([up.Request](https://unpoly.com/api/up.Request.md)): boolean

#### [config.expireCache] {#config.expireCache}

(optional)

A function that controls [cache expiration](https://unpoly.com/learn/caching.md#expiration) when the given request is sent.

Returning `true` will expire the entire cache.
Returning `false` will not expire any cache entries.
Returning a [URL pattern](https://unpoly.com/api/url-patterns.md) will expire matching cache entries only.

By default, Unpoly will expire the entire cache when it sends a request with an [unsafe](https://developer.mozilla.org/en-US/docs/Glossary/Safe/HTTP) HTTP method:

```js
up.request({ url: '/path', method: 'get' })  // no cache entries expired
up.request({ url: '/path', method: 'post' }) // entire cache expired
```

Type: Function([up.Request](https://unpoly.com/api/up.Request.md)): boolean|string | boolean

#### [config.evictCache=false] {#config.evictCache}

(optional)

A function that controls [cache eviction](https://unpoly.com/learn/caching.md#eviction) when the given request is sent.

Returning `true` will evict the entire cache.
Returning `false` will not evict any cache entries.
Returning a [URL pattern](https://unpoly.com/api/url-patterns.md) will evict matching cache entries only.

By default, Unpoly will _not_ evict any cache entries when a request is sent.

Type: Function([up.Request](https://unpoly.com/api/up.Request.md)): boolean|string | boolean

#### [config.progressBar] {#config.progressBar}

(optional)

Whether to show a [progress bar](https://unpoly.com/learn/progress-bar.md) for [late requests](#config.lateDelay).

Type: boolean | Function(): boolean

