Skip to content

Commit

Permalink
Document events dispatched during preloading
Browse files Browse the repository at this point in the history
Documents [@hotwired/turbo#1034][]

Document the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events dispatched during `<a>` preloading.

[@hotwired/turbo#1034]: hotwired/turbo#1034
  • Loading branch information
seanpdoyle committed Oct 12, 2023
1 parent 661a229 commit 11549a8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _source/handbook/02_drive.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,9 @@ Preload links into Turbo Drive's cache using `<a href="/" data-turbo-preload>Hom

This will make page transitions feel lightning fast by providing a preview of a page even before the first visit. Use it to preload the most important pages in your application. Avoid over usage, as it will lead to loading content that is not needed.

Note that preloaded `<a>` elements will dispatch [turbo:before-fetch-request](/reference/events) and [turbo:before-fetch-response](/reference/events). Determine whether a `turbo:before-fetch-request` event is a preload request by checking the [Sec-Purpose:][] header (accessible from the `event.detail.fetchOptions.headers["Sec-Purpose"]` property).

It also dovetails nicely with pages that leverage [Eager-Loading Frames](/reference/frames#eager-loaded-frame) or [Lazy-Loading Frames](/reference/frames#lazy-loaded-frame). As you can preload the structure of the page and show the user a meaningful loading state while the interesting content loads.
<br><br>

[Sec-Purpose:]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose#prefetch

0 comments on commit 11549a8

Please sign in to comment.