Comment: HTML5's link prefetching function (link prefetching) is a gem buried in the sand. Few people still know its value. Friends who need it can learn about it.
HTML5's link prefetching function (link prefetching) is a gem buried in the sand, and few people still know its value. You may already know the ancient and famous image preloading function, and the link prefetch function is to extend this concept from images to web content (no AJAX code is required).
It works like this: Add a link like this to the page:
<link href="page2.html">
In this way, when your machine is idle, the browser will automatically download page2.html in the background. When the user finally clicks on the page2.html link, the browser will take the page out of the cache, so the loading speed of this page will be unexpectedly fast.
Currently, only Firefox browser supports this function. However, because Firefox is currently the browser with the second largest user base in the world, as long as you add such a code to the HTML page, a considerable number of visitors can still experience this very obvious improvement in page loading speed. Very cool!
You can use the link prefetch feature in many cases:
* When you have a long article, online tutorial, picture album, etc., that needs to be displayed in multiple pages.
* Preload the next page that users are most likely to visit on your website homepage. (Maybe it is a product page that recommends a product website, or a recent blog post on a blog website)
* The search query page preloads the first few items that were searched for.
For static content, you can also use rel tags to implement prefetching function:
<link href="/images/big.jpeg?ca541d">
There are some other interesting things to note here:
* The link prefetching function will soon be implemented in Opera, Chrome and Safari browsers, but for Internet Explorer, you probably have to wait until 2020.
* If this feature is widely used, it will affect your website logs and access statistics. Please consider this situation. One of your pages has pre-releases and withdrawns several pages, but the user actually has not accessed these pages. Your server (or statistics tool) doesn't know the difference between the two.
In order to distinguish this, Firefox will send X-moz: prefetch information in HTTP header information, but you need something to identify this information on the server side.