inertia
inertia copied to clipboard
Example: Link preloading (GET-only)
This functionality adds a 'request manager' of sorts, which has the following behavior:
- If there is no request, it starts the request and returns a promise that will eventually resolve (or fail)
- If the request is pending, it hooks a promise-resolver into the existing request, which will resolve (or fail) once completed.
- If the request has successfully finished, it returns a promise that instantly resolves to the (cached) request.
- If the prefetch request failed, it'll start a new request (see 1)
In all situations, in addition to the promise, you'll receive a cancel hook, so that if you want to cancel the individual visit.
This request manager has been implemented to pre-load GET requests on-hover (see https://instant.page/ for what it's supposed to do), as well as to cancel all 'pending' requests once the page switches.
Solves #45