API
Network requests
module
up.network
This package implements an optimized HTTP client that is used for all requests made through Unpoly.
The HTTP client offers many quality-of-life improvements, for example:
- Requests may be cached to re-use responses and enable preloading. Cached content is revalidated after rendering, so the user never sees stale content.
- You may handle network issues, such as disconnects, flaky connections or low bandwidth.
- A progress bar is shown when requests take too long to finish.
- When two requests target the same element, Unpoly will abort the earlier request.
- Requests send additional HTTP headers that the server may use to optimize its response.
For example, when updating a fragment, the target selector is automatically sent
as an
X-Up-Targetheader. The server may choose to only render the targeted fragment. - Useful events like
up:request:loadedorup:network:lateare 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.
Unpoly's HTTP client is used automatically when rendering, e.g. when following a link
or submitting a form. To use the client from your own JavaScripts, use up.request().
Guides
Features
Essentials
Makes an AJAX request to the given URL.
This event is emitted when AJAX requests are taking long to finish loading.
All features
JSMakes an AJAX request to the given URL and caches the response.
Makes the cache assume that newRequest has the same response as the
already cached oldRequest.
Expires cache entries.
Evicts responses in the cache.
Expires entries in the cache.
Returns a cached request matching the given request options.
Aborts pending requests matching a condition.
Sets default options for network requests.
Returns whether Unpoly is currently loading a request.
Returns whether Unpoly is not currently loading a request.
This event is emitted when AJAX requests are taking long to finish loading.
Makes a full-page request, replacing the entire browser environment with a new page from the server response.
This event is emitted when AJAX requests have taken long to finish, but have finished now.
Expires all cache entries.
Preloads the given link.
Makes an AJAX request to the given URL.
This event is emitted when an AJAX request was aborted.
This event is emitted before an AJAX request is sent over the network.
This event is emitted when the response to an AJAX request has been received.
This event is emitted when an AJAX request encounters a fatal error, like a timeout or loss of network connectivity.
