Edit this page

API Network requests
module up.network

Unpoly ships with an optimized HTTP client for fast and effective communication with your server-side app.

While you can use the browser's native fetch() function, Unpoly's up.request() has a number of convenience features:

  • Requests may be cached to reuse responses and enable preloading.
  • Requests send additional HTTP headers that the server may use to optimize its response. For example, when updating a fragment, the fragment's selector is automatically sent as an X-Up-Target header. The server may choose to only render the targeted fragment.
  • Useful events like up:request:loaded or up:request:late are emitted throughout the request/response lifecycle.
  • When too many requests are sent concurrently, excessive requests are queued. This prevents exhausting the user's bandwidth and limits race conditions in end-to-end tests.
  • A very concise API requiring zero boilerplate code.

Essential features

All features

JS
up.ajax([url], [options]) deprecated

Makes an AJAX request to the given URL and caches the response.

JS
up.cache.alias(oldRequest, newRequest) experimental

Makes the cache assume that newRequest has the same response as the already cached oldRequest.

JS
up.cache.clear([pattern]) stable

Removes all cache entries.

JS
up.cache.get(requestOptions) experimental

Returns an earlier request matching the given request options.

JS
up.cache.remove(requestOptions) experimental

Manually removes the given request from the cache.

JS
up.network.abort([matcher]) stable

Aborts pending requests.

JS
up.network.config stable

Sets default options for this package.

JS
up.network.isBusy() stable

Returns whether Unpoly is currently waiting for a request to finish.

JS
up.network.isIdle() stable

Returns whether Unpoly is not currently waiting for a request to finish.

JS
up.network.loadPage(options) experimental

Makes a full-page request, replacing the entire browser environment with a new page from the server response.

JS
up.network.shouldReduceRequests() experimental

Returns whether optional requests should be avoided where possible.

JS
up.proxy.clear() deprecated

Removes all cache entries.

JS
up.request([url], [options]) stable

Makes an AJAX request to the given URL.

JS
up:request:aborted experimental

This event is emitted when an AJAX request was aborted.

JS
up:request:fatal stable

This event is emitted when an AJAX request encounters fatal error like a timeout or loss of network connectivity.

JS
up:request:late stable

This event is emitted when AJAX requests are taking long to finish.

JS
up:request:load stable

This event is emitted before an AJAX request is sent over the network.

JS
up:request:loaded stable

This event is emitted when the response to an AJAX request has been received.

JS
up:request:recover stable

This event is emitted when AJAX requests have taken long to finish, but have finished now.

This website uses cookies to improve usability and analyze traffic.
I accept or learn more