Sets default options for this package.
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.
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).
The maximum number of responses to cache.
If the size is exceeded, the oldest responses will be dropped from the cache.
How long to wait before emitting the up:network:late
event.
Requests exceeding this response time will also cause a progress bar to appear at the top edge of the screen.
The value is given in milliseconds.
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.
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.
The number of milliseconds after which a cache entry is evicted.
In practice you will often prefer expiration over eviction.
Defaults to 90 minutes.
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')
}
Whether to expire the cache after the given request and response.
By default Unpoly will expire the entire cache after a request with an unsafe HTTP method.
The configured function can either return a boolean or an URL pattern matching responses that should be expired.
Whether to evict the cache after the given request and response.
The configured function can either return a boolean or an URL pattern matching responses that should be evicted.
By default Unpoly will not evict any cache entries when a request is made.
For example, to evict the entire cache after a request with an unsafe HTTP method:
up.network.config.evictCache = (request) => !request.isSafe()
Whether to show a progress bar for late requests.