
document
应用缓存创建文件为:index.html
Hello HTML5!
接下来创建文件为:index.appcache
CACHE MANIFESTCACHE:
index.html
index.js
NETWORK:
style.css
用chrome打开index.html后检查元素就会发现index.html index.js缓存下来了,而style.css没有缓存。
## web workers
1. 什么是Web Worker?
web worker是运行在后台的Javascript,独立于其他脚本,不会影响页面的性能
2. 方法:
postMessage()-它用于向HTML页面传回一段消息
terminate()-终止web worker,并释放浏览器/计算机资源
3. 事件:
onmessage
#### 代码示例
创建主文件:index.html
```html
0
创建:index.js
var 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.js
var countNum = 0;
function count(){
postMessage(countNum);
countNum++;
setTimeout(count,1000);
}
count();
作者:cllgeek
github:cll