標籤:沒有 man 更新 程式 釋放 term top return 效能
1.什麼是應用程式緩衝 HTML5引入了應用程式緩衝,這意味著web應用可進行緩衝,並可在沒有網際網路連結時進行訪問。2.應用緩衝的優勢 離線瀏覽 使用者可在應用離線時使用它們 速度 已緩衝資源載入得更快 減少伺服器負載 瀏覽器將只從伺服器下載更新過或更改過的資源3.實現緩衝 如需啟用應用程式緩衝,請在文檔的<html>標籤中包含manifest屬性 manifest檔案的建議的副檔名是:“.appcache”4.Manifest檔案: CACHE MANIFEST 在此標題下列出的檔案將在首次下載後進行緩衝 NETWORK 在此標題下列出的檔案需要與伺服器的連結,且不會被緩衝 FALLBACK 在此標題下列出的檔案規定當頁面無法訪問時的回退頁面(比如404頁面) <!DOCTYPE html><html manifest="index.appcache"><head lang="en"> <meta charset="UTF-8"> <title></title> <script src="index.js"></script></head><body> <h1 class="h1">hello world!</h1></body></html> 需要在 .appcache檔案裡面寫CACHE MANIFEST CACHE:index.htmlstyle.cssindex.js
Web Worker1.什麼是Web Worker web worker 是運行在背景JavaScript, 獨立於其他指令碼 , 不會影響頁面的效能2.方法 postMessage() 它用於向HTML頁面傳回一段訊息 terminate() 終止 web worker , 並釋放瀏覽器/電腦資源3.事件 onmessage <!doctype html><html lang="en"><head> <meta charset="UTF-8"> <title>數字累加</title> <script src="app.js"></script></head><body> <div id="numDiv">0</div> <button id="start">start</button> <button id="stop">stop</button></body></html> //app.jsvar numDiv;var work=null; window.onload=function(){ numDiv=document.getElementById("numDiv"); document.getElementById("start").onclick=startWorker; document.getElementById("stop").onclick=function(){ if(work){ work.terminate(); work=null; } } } function startWorker(){ if(work){ return; } work= new Worker("count.js"); work.onmessage=function(e){ numDiv.innerHTML= e.data; }} //count.jsvar countNum=0;function count(){ postMessage(countNum); countNum++; setTimeout(count,1000);}count();
HTML5應用緩衝與Web Workers