Describes how to use the prefetch preload function of the rel attribute in HTML5, html5rel

Source: Internet
Author: User
Tags prefetch chrome developer chrome developer tools

Describes how to use the prefetch preload function of the rel attribute in HTML5, html5rel

In HTML5, a very useful but often overlooked feature is prefetch. Its principle is:
The browser's free time is used to download the content specified by the user and then cache the content. This way, the user can directly obtain the content from the cache next time the user loads the file, and the efficiency is faster.

For example, to pre-load a page, you can:

XML/HTML Code

However, if it is google, use another name, namely:

XML/HTML Code

Even in browsers that do not support this feature, it will not be wrong, but the browser cannot parse it,
Therefore, if you feel that you can predict the page expected by the user in advance (for example, if the user looks at the latest popular heat map, he may continue to read the next page after reading the first page, this feature can be preloaded at this time ). for example

XML/HTML Code

It is also possible to retrieve an image separately, for example:

XML/HTML Code

Why do I need to pre-load the browser cache?
1. The user may be visiting the website for the first time and there is no cache
2. The user may have cleared the cache.
3. the cache may have expired and the resource will be reloaded.
4. the cached files accessed by the user may not be up-to-date and need to be reloaded.
5. Chrome's pre-loading technology
Currently, chrome is smart enough to predict which websites you may visit or search based on your browsing history. Some resources are loaded before you open the website.
For example, when you enter "amaz" in the search box, it guesses that you may want to access amazon.com, which may help you load some resources of this website.
If this prediction algorithm is accurate, it will greatly improve the user's browsing experience.

DNS prefetch
We know that when we access a website such as www.amazon.com, we need to first convert this domain name to the corresponding IP address, which is a very time-consuming process.
DNS prefetch analyzes the Domain Name of the resources required on this page. When the browser is idle, it will convert these domain names into IP addresses in advance, which avoids the above process when actually requesting resources.

XML/HTML Code

Application Scenario 1: our resources exist in different cdns. If we declare the domain names of these resources in advance, we can save the time for domain name resolution when requests occur.
Application Scenario 2: If we know that the user's subsequent operations will initiate a resource request, we can perform DNS-Prefetch on this resource to enhance the user experience.

Resource prefetch
In Chrome, we can use the link label to declare the pre-loading of a specific file:

XML/HTML Code

In Firefox or with meta tag declaration:

XML/HTML Code

Rel = 'subresource' indicates the resources that must be loaded on the current page. It should be loaded first at the top of the page, with the highest priority.
Rel = 'prefetch' indicates that when all the subresource resources are loaded, the specified resources are preloaded with the lowest priority.
Note: Only cache-able resources are pre-loaded; otherwise, resources are wasted!

Pre render
The Pre-resolution DNS and Pre-loading resources mentioned above are already powerful enough, but there are more advanced Pre-rendering resources )!
Pre-rendering means that we load the next page that the user will visit in advance. Otherwise, pre-rendering this page will waste resources and use it with caution!

XML/HTML Code

Rel = 'prerender' indicates that the browser will render but hide the specified page. Once we access this page, the browser will open in seconds!
Use rel = 'Next' in Firefox to declare

XML/HTML Code

Not all resources can be preloaded.
When the resource is a resource in the following list, the pre-rendering operation is blocked:
1. the URL contains the downloaded resource.
2. The page contains audio and video
3. ajax requests for POST, PUT, and DELETE operations
4. HTTP Authentication)
5. HTTPS page
6. pages containing malware
7. Pop-up page
8. pages that occupy a lot of resources
9. Opened the chrome developer tools development tool.

Manually trigger the pre-rendering operation
Insert link [rel = 'prerender'] in the header:

JavaScript Code

 

Address: http://www.link588.com/html/wangyezhizuo/135759.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.