溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Html5中prefetch和prerender有什么用

發(fā)布時(shí)間:2021-09-17 11:43:12 來(lái)源:億速云 閱讀:143 作者:小新 欄目:web開(kāi)發(fā)

這篇文章主要介紹Html5中prefetch和prerender有什么用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

prerender / prefetch

其實(shí)是為了提升網(wǎng)頁(yè)加載速度而但是一直通過(guò)預(yù)加載來(lái)實(shí)現(xiàn),提升用戶(hù)感受的方式,例如用戶(hù)在首頁(yè)停留2s, 而這2s里面我們就已經(jīng)加載了一個(gè)用戶(hù)可能要打開(kāi)的頁(yè)面,那么用戶(hù)打開(kāi)的速度會(huì)非??? 給用戶(hù)的感受也是極好的

HTML5 Prerender / Prefetch名詞解釋

prefetch usage:

It should be used for fetching and caching resources for later user navigation as per the official HTML5 spec (i.e. prefetching a css file to be used in a page which highly likely to be used by the user in his upcoming navigation). Supported in Chrome, Firefox & IE.

簡(jiǎn)單說(shuō)就是緩存下一個(gè)網(wǎng)頁(yè)的資源,是HTML5的新特性, 支持的瀏覽器有Chrome(13以后),  Firefox, IE 11

prerender usage:

It should be used for prerendering a complete page that the user will highly likely navigate to it in his upcoming navigation (i.e. like prerendering the next article where it is highly likely that the user will click on “next article” button). Supported only in Chrome & IE.

Prerender是Google的一個(gè)發(fā)明,正在提升用戶(hù)減少用戶(hù)在加載時(shí)的等待, 通過(guò)最相近匹配原則來(lái)加載例如“下一頁(yè)”的文章., 例如最佳推薦,當(dāng)用戶(hù)訪問(wèn)A頁(yè)面的時(shí)候, 用戶(hù)最可能訪問(wèn)的下一個(gè)頁(yè)面上B 那么就預(yù)加載B頁(yè)面, 以達(dá)到提升加載速度的效果, 支持的瀏覽器有Chrome , IE11

使用方法

is actually part of the HTML 5 spec.
appears to be Google doing their own thing.

第一中方法是 將以上鏈接添加到xxx

第二種方法是 使用JS代碼注入方式;

var myHead = document.getElementsByTagName(‘head’)[0];
var myLink = document.createElement(‘link’);
myLink.setAttribute(‘rel’, ‘prerender’);
myLink.setAttribute(‘href’, ‘http://apple.com/ipad’);
myHead.appendChild(myLink);

或者使用Jquery方法:

$(“head”).append(‘www.guoli.biz/’);

以上是“Html5中prefetch和prerender有什么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI