I see this repo frequently nowadays and I feel like I have to go a bit against it. Sorry. 😕
TLDR: This goes nicely with some server rendered and static pages but not so nicely with SPAs.
Prefetching is an amazing tool but it is meant to be used selectively, in context-specific use cases. Making all links into a prefetch one is not a good idea, if it would be the browser devs would have done that instead of giving us an API.
This does prefetch pages on hover but prefetching a page only involves fetching the entry point (index.html), it does not fetch secondary resources. A lot of modern pages have tiny index.html files and huge secondary bundles (JS and CSS). In this case prefetching has no impact and server push or a PWA could be utilized better.
Most SPA routers use 'fake' a tags (with prevented default event handling) under the hood for client-side routing. This is done to combine the best parts new-school and old-school routing - like keeping the right-click 'Open in new tab' functionality. Prefetching on hover events over these 'fake' a tags will simply fetch your SPAs index.html once more. This is just added network traffic with zero value.
There are so much more that can be prefetched, apart from links and whole pages. Just always pay attention when you add a new resource and decide if it benefits from prefetching. It is usually not a big overhead.
I think this is a witty idea and the code looks very clean though. Also props for raising awareness regarding the newish prefetch capability!
EDIT: I wrote this based on my personal experience, without getting into the spec. Please correct me if I mentioned something incorrect.
Totally okay with your view about this. I should have added a disclaimer that it works best with static sites or server rendered sites. I'm currently using it for a static site and it works well.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I see this repo frequently nowadays and I feel like I have to go a bit against it. Sorry. 😕
TLDR: This goes nicely with some server rendered and static pages but not so nicely with SPAs.
Prefetching is an amazing tool but it is meant to be used selectively, in context-specific use cases. Making all links into a prefetch one is not a good idea, if it would be the browser devs would have done that instead of giving us an API.
This does prefetch pages on hover but prefetching a page only involves fetching the entry point (index.html), it does not fetch secondary resources. A lot of modern pages have tiny index.html files and huge secondary bundles (JS and CSS). In this case prefetching has no impact and server push or a PWA could be utilized better.
Most SPA routers use 'fake'
a
tags (with prevented default event handling) under the hood for client-side routing. This is done to combine the best parts new-school and old-school routing - like keeping the right-click 'Open in new tab' functionality. Prefetching on hover events over these 'fake'a
tags will simply fetch your SPAs index.html once more. This is just added network traffic with zero value.There are so much more that can be prefetched, apart from links and whole pages. Just always pay attention when you add a new resource and decide if it benefits from prefetching. It is usually not a big overhead.
I think this is a witty idea and the code looks very clean though. Also props for raising awareness regarding the newish prefetch capability!
EDIT: I wrote this based on my personal experience, without getting into the spec. Please correct me if I mentioned something incorrect.
Totally okay with your view about this. I should have added a disclaimer that it works best with static sites or server rendered sites. I'm currently using it for a static site and it works well.