一.离线存储css
有一个web应用有三个文件index.html,a.js,b.css,如今须要把js和css文件缓存起来html
1.在index.html里加上<html manifest="test.manifest">web
2.manifest清单格式以下chrome
CACHE MANIFEST
#上面一句必须
#v1.0.0
#须要缓存的文件
CACHE:
a.js
b.css
#不须要缓存的文件
NETWORK:
*
#没法访问页面
FALLBACK:
404.html
3.manifest文件的mime-type必须是 text/cache-manifest类型浏览器
注意点:缓存
1.对于每一个index.html?id=1或index.html?id=2都会分别缓存index.html页面,能够经过chrome浏览器Resources/Application Cache观察app
2.若是想更新缓存内容,只要修改下manifest文件便可,如改版本号v1.0.1spa
4.离线存储若是资源有更新,能够经过以下代码来监听,但第一次加载还会是原来的版本code
window.applicationCache.addEventListener('updateready',function(e){ if(window.applicationCache.status == window.applicationCache.UPDATEREADY){ window.applicationCache.swapCache(); if(confirm("loding new?")){ window.location.reload() } } },false)
二.本地缓存htm
localStorage.setItem("key","value") localStorage.getItem("key","value") localStorage.removeItem("key") localStorage.clear()
1.本地存储永不过时,除非本身去清除
2.能够经过chrome浏览器Resources/Local Storage来查看
3.不一样域下就算key相同取不到的值也不一样,如localhost和127.0.0.1