HTML5應用緩衝與Web Workers

來源:互聯網
上載者:User

標籤:沒有   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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.