Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

html - How can I preload a page using HTML5?

I remember reading about a meta tag that makes the browser preload a page. What's the tag again?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Prefetching is included in a W3C spec under the name Resource Hints. It is implemented in Firefox, Chrome, IE 11, Edge, Opera after 12.1, and the Android Browser from 4.4.4, see the caniuse prefetch page for more and up-to-date details.

Also see the caniuse and spec pages for related technologies (supported browsers afterwards are retrieved from caniuse and up-to-date as of September 2015):

  • Prerendering caniuse / spec (IE 11, Edge, Chrome, Opera)
  • Preconnecting caniuse / spec (Firefox, Chrome 46, Opera 33)
  • DNS Prefetching caniuse / spec (IE9 (see note below), IE10, every other browser except Opera Mini and perhaps iOS Safari and the Android Browser)

IE 9 implemented DNS prefetching only but called it "prefetch" (caution!). Chrome for a while (at least as far as 2013) only did prerendering and DNS prefetching. IE11 implements lazyload, for images; Microsoft has tried to get it in the spec but so far it isn't. iCab is stated to have been the first browser to implement prefetching, although this behaviour was automatic, not controlled by the markup.


Historical background

The Mozilla Application Suite, and later, Firefox, implement the spec (the spec is actually based on Mozilla's early implementation of prefetching, which was somewhat based on the Link: header specified in RFC 2068 which has now been superseeded by RFC 2616 [which does not reference the Link: header]. See this old version of the docs (??) for more detail.) As per the documentation on 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.

The browser looks for either an HTML <link> or an HTTP Link: header with a relation type of either next or prefetch.

So the syntax is:

<link rel="prefetch" href="/path/to/prefetch" />

You can also use the Link: HTTP header:

Link: </page/to/prefetch>; rel=prefetch

Or a <meta> to simulate that same HTTP header:

<meta http-equiv="Link" content="&lt;/page/to/prefetch&gt;; rel=prefetch">

Note that the next relation can also be used, but its main function is to indicate the "next" page in the navigation, so you should not use it for resources or unrelated information. Prefetching is also performed on HTTPS connections.

iCab

iCab seems to (??) have implemented an early prefetching around 2001. iCab apparently prefetched all links to content pages (not resources), not following any hint the developer would have left in the markup.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...