Improving Page Performance with HTML5 Prefetch
As Wikipedia explains:
Link prefetching is a proprietary syntax to give web browsers a hint about documents that it should pre-fetch because the user might visit them in the near future. It is proposed as a draft internet standard by Mozilla. A web page provides a set of prefetching hints to the browser, and after the browser is finished loading the page, and after an idle time has passed, it begins silently prefetching specified documents, storing them in its cache. When the user visits one of the prefetched documents, it can be served up quickly out of the browser's cache.
Firefox introduces a new strategy for website optimization: link prefetching. (learn more about Firefox’s prefetching)
So, what is link prefetching? From the MDN:
Link prefetching is a browser mechanism, which utilizes browser idle time to download or prefetch documents that the user might visit in the near future. A web page provides a set of prefetching hints to the browser, and after the browser is finished loading the page, it begins silently prefetching specified documents and stores them in its cache. When the user visits one of the prefetched documents, it can be served up quickly out of the browser's cache.
It's super easy to implement: the browser downloads designated documents (pages, images, etc.) the user will likely visit after the current page.
Prefetching pages with HTML5
HTML5 introduces prefetching, the art of loading pages before the user requested them. In this post, we are going to discuss this technique as well as showing you some ready to use examples to drastically improve your website loading time.
The only thing you have to do is to place the following code with the <head> and </head> tags of your page. The href attribute have to contain the url of the page to prefetch.
<link rel="prefetch" href="http://www.example.com/">
It is also possible to prefetch an image:
<link rel="prefetch" href="http://www.ma-no.org/assets/img/logos/mano-logo.png">
HTML5 prefetching is done via the LINK tag, specifying "prefetch" as the rel and the href being the path to the document. Mozilla also answers to a few differently named LINK rel attributes:
<link rel="prefetch alternate stylesheet" title="Designed for Mozilla" href="mozspecific.css" /> <link rel="next" href="2.html" />
HTTPS fetches are also supported.
Firefox allows you to disable link prefetching with the following setting snippet:
But when and where is convenient to Prefetch Content?
Well, is up to you! Here are some ideas:
- When a series of pages is much like a slideshow, load the next 1-3 pages, previous 1-3 pages (assuming they aren't massive).
- Loading images to be used on most pages throughout the website.
- Loading the next page of the search results on your website.
- Tools to build PWA quickly
- A roadmap to becoming a web developer in 2019
- Designers and Marie Kondo: a life lesson
- The Meaning of Colors in web Design. A little bit of psychology
- Parallax Landscape Scenes Built Entirely With CSS and HTML
- The Most Useful 50 Web Sites you wish you knew earlier
- Six Ways to Make Your Design Brand Stand Out with a Portfolio
- Fullscreen Background Video HTML5 And CSS cross-browser
- UX-UI: How to design better forms