Edit this page

up.network up.network.config
Configuration object

Sets default options for network requests.


Requests

[config.concurrency]
optional

The maximum number of concurrently loading requests.

Additional requests are queued. Preload 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.

numberFunction(): number
[config.wrapMethod=true]
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 carry their original method as a _method parameter. This is to prevent unexpected redirect behavior.

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

boolean
[config.lateDelay=400]
optional

The number of milliseconds to wait before emitting the up:network:late event and showing the progress bar.

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

numberFunction(up.Request): numberboolean
[config.timeout=90_000]
optional

A default timeout for requests in milliseconds.

Set undefined to not use a timeout.

numberundefined
[config.fail]
optional

Whether Unpoly will consider a response to constitute a failed response.

By default Unpoly will consider any status code other than HTTP 2xx or 304 to represent a failed 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:

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

Also see Customizing failure detection.

booleanFunction(up.Response): boolean

Caching

[config.cacheSize=70]
optional

The maximum number of responses to cache.

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

number
[config.cacheExpireAge=15_000]
optional

The number of milliseconds after which a cache entry is considered expired and will trigger revalidation when used.

The configured age should at least cover the average time between preloading and following a link.

Defaults to 15 seconds.

number
[config.cacheEvictAge=90*60*1000]
optional

The number of milliseconds after which a cache entry is evicted.

In practice you will often prefer expiration over eviction.

Defaults to 90 minutes.

number
[config.autoCache]
optional

Whether to cache the given request with { cache: 'auto' }.

By default Unpoly will auto-cache requests with safe 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:

let defaultAutoCache = up.network.config.autoCache
up.network.config.autoCache = function(request) {
  return defaultAutoCache(request) && !request.url.endsWith('/edit')
}
Function(up.Request): boolean
[config.expireCache]
optional

A function that controls cache expiration before the given request loads.

Returning true will expire the entire cache.
Returning false will not expire any cache entries.
Returning a URL pattern will expire matching cache entries only:

By default Unpoly will expire the entire cache after a request with an unsafe HTTP method:

up.request({ url: '/path', method: 'get' })  // no cache entries expired
up.request({ url: '/path', method: 'post' }) // entire cache expired
Function(up.Request): boolean|stringboolean
[config.evictCache=false]
optional

A function that controls cache eviction before the given request loads.

Returning true will expire the entire cache.
Returning false will not expire any cache entries.
Returning a URL pattern will expire matching cache entries only.

By default Unpoly will not evict any cache entries when a request is made.

Function(up.Request): boolean|stringboolean
[config.progressBar]
optional

Whether to show a progress bar for late requests.

booleanFunction(): boolean