instantpage / instant.page

Make your site’s pages instant in 1 minute and improve your conversion rate by 1%
https://instant.page
MIT License
6.04k stars 205 forks source link

Expiring preloaded content #54

Closed thijsvandien closed 4 years ago

thijsvandien commented 4 years ago

Thanks for this great library! I was wondering about a certain edge case:

Let's say a visitor lets their mouse sit on a link for a while. The content is preloaded right away (on hover). By the time they actually click, it might already be slightly stale. Is there anything that will cause the content to be preloaded again after some time, or a regular load of fresh content to happen after all? Would I have any influence over that (e.g. set the expiry time)?

csswizardry commented 4 years ago

Any Cache-Control headers that would require a revalidation will be honoured, so things like no-cache, must-revalidate will cause a network round trip to at least revalidate the file. no-store would completely negate the use of prefetch, effectively causing double downloads. Interestingly, assets over five minutes old will be revalidated regardless of what their headers permit.

dieulot commented 4 years ago

At least in Chrome the Age header is taken into account, if it’s over 300 (5 minutes) prefetch won’t have any effect. If you want the content to be re-downloaded if the user has hovered for 10 seconds, set the Age header to 290 for instance.

Out of curiosity, what kind of content makes you worry about that? I’ve used just-in-time preloading on a very highly active forum and I didn’t consider it a problem there.

thijsvandien commented 4 years ago

I was thinking about web apps with semi-live data. 5 minutes are not expected to be an issue, but when asking the question I did not know whether it would be possible for results to be hours old in this case, which would be problematic.