inertia icon indicating copy to clipboard operation
inertia copied to clipboard

Example: Link preloading (GET-only)

Open claudiodekker opened this issue 5 years ago • 0 comments

This functionality adds a 'request manager' of sorts, which has the following behavior:

  1. If there is no request, it starts the request and returns a promise that will eventually resolve (or fail)
  2. If the request is pending, it hooks a promise-resolver into the existing request, which will resolve (or fail) once completed.
  3. If the request has successfully finished, it returns a promise that instantly resolves to the (cached) request.
  4. 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

claudiodekker avatar Sep 18 '20 11:09 claudiodekker