Preloading visits #45
Replies: 6 comments 3 replies
-
@sebastiandedeyne see Google quicklink too |
Beta Was this translation helpful? Give feedback.
-
I like the idea of prefetching page states when an Inertia link with a What do you think @reinink? I could whip up a proof of concept. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi all! I stumbled across this when trying to think of a way to "prefetch" paginated data - looks like this discussion is over 2 years old but I wanted to see if maybe it is already done and/or reboot the conversation. In my use case I am consuming a third party API (Twilio) on the Laravel server side - but I wanted to share and get some feedback. I am paginating the results from Twilio REST API. What I did on the Laravel backend is cache the page results of data already consumed via the Twilio REST API - so that if a user was navigating back and forth it reduces the API requests and keeps the page loading fast. Since I was already caching the returned responses on the server side, I was thinking to basically make a request on the VueJS/Inertia side to the next url. This way when the page is loaded, if there is a next url we make a background call to the next url (which would create the cache). Now when the user clicks the link - it was cached on the previous pages load so no waiting. What if Inertia was following something similar when a component has a prefetch attribute it tells inertia to subsequently cache the next dataset url after loading the first response. |
Beta Was this translation helpful? Give feedback.
-
Well let me know if there is any contributions I can help with. I got it working on my current project using pagination components, middleware and interceptors. I basically created vue pagination components. Added an interceptor and responses on the front end that looks for a X-Prefetch-* header where * is the variable in response name - so for each header it will look at the response and queue up the request. On the laravel side using a middleware I am catching "pagination" data, then setting the header with the previous and next page url. It basically hits a special cache URL that mimics the users request in a QUEUE JOB to cache the results. This way the moment the user clicks next Laravel has already cached the next page. Each subsequent page load is caching the next only when the user visits not the QUEUE job. User experience is super fast - especially on paginated data. I used Nova for an admin site and found it to be slow from time to time when working with large data and this literally solves it. I need to create special route keys still so that on that routes model changes it resets the cache to make sure that the data is not stale. |
Beta Was this translation helpful? Give feedback.
-
Checking back at the end of 2024--is there any prefetch / preload logic built into Inertia at this point? Or any promising merge requests? |
Beta Was this translation helpful? Give feedback.
-
It would be great if we would be able to preload visits before the user clicks a link. This would be opt-in behaviour per link.
Next.js does this pretty good:
https://github.com/zeit/next.js#prefetching-pages
With the way Inertia works this could be very difficult to implement. I currently see two things we could preload:
We could build something like InstantClick, that prefetches the next page in the background when the user hovers over a link, or when we add a
prefetch
attribute to the link.The problem here is that we'd be prefetching the html, but not the JavaScript chunk needed for the next page.
Ideally we would be able to preload the script for the next page's component. However, Inertia has no knowledge which URL's map to which chunks, so I have no idea how this could work.
Any input on this matter is appreciated!
Beta Was this translation helpful? Give feedback.
All reactions