Preloading is done with <link rel="prefetch" href="url">.
The source code is 170 readable lines.
instant.page is progressive enhancement — there’s no impact on browsers that don’t support it.
Chrome has full support.
Firefox supports <link rel="prefetch"> but will redownload the page if it’s not cached. The popular extension uBlock Origin disables prefetching.
Safari doesn’t support <link rel="prefetch">. The upcoming version 13 supports it, but it’s disabled by default. Hopefully it will be enabled in March.
UC Browser doesn’t support modules, but it should support them later this year as a new version based on Chrome 69 is in preparation.
Edge doesn’t support <link rel="prefetch"> but is going to adopt Chrome’s engine which does.
instant.page’s script is hosted serverless with Cloudflare Workers so that there’s no server to hack into.
Cloudflare provided me with free Workers in order to be able to securely serve the script to a potentially very large number of people.
Additionally, it uses subresource integrity to let modern browsers verify that the file hasn’t been tampered with. It’s loaded as a module so that most old browsers won’t execute it.
The only browser versions that implement modules without implementing subresource integrity are Edge 16, Safari 10.1 and Safari 11.0. They account for 0.8% of page views.
Hosting the script yourself is also possible. Download the latest version then add a module script tag just before </body>:
<script src="instantpage-2.0.0.js" type="module" defer></script>
You can also install it via npm:
npm i instant.page
The idea of preloading web pages on hover and touchstart comes from an older library of mine, InstantClick, which uses Ajax and history.pushState instead of <link rel="prefetch">, transforming a site into a single-page application. It makes a site even smoother but requires additional work.
InstantClick is unfortunately mostly just a proof of concept as it doesn’t have good documentation.
Google’s recent release of quicklink, which preloads links with <link rel="prefetch"> as soon as they are shown, made it clear that I should focus on building a “lite”, easier to use version of InstantClick, which is instant.page.
Future related projects
InstantClick provides one of the smoothest experiences possible, while still not requiring as much work as a framework (who give lesser results), so I’m considering working on it again later on.
I also plan to research how this just-in-time preloading concept might fit into React/Vue/Angular, as those are popular and incompatible with InstantClick’s simplified SPA model. (I currently have no experience with those frameworks.)
<script src="//instant.page/2.0.0" type="module" defer integrity="sha384-D7B5eODAUd397+f4zNFAVlnDNDtO1ppV8rPnfygILQXhqu3cUndgHvlcJR2Bhig8"></script>