localStorage和sessionStorage支持的方法
setItem(key,value),getItem(key),removeItem(key),clear(),存储事件(storage)
使用key()和length,可以枚举所有存储数据的名字

for(var i=0;l<localStorage.length;i++){
    var name = localStorage.key(i)
    var value = localStorage.getItem(name)
}

当存储数据发生变化时,触发存储事件(storage)

document.addEventListener('storage', () => {
    // When local storage changes, dump the list to
    // the console.
    console.log(JSON.parse(window.localStorage.getItem('sampleList')));    
});
window.onstorage = () => {
    // When local storage changes, dump the list to
    // the console.
    console.log(JSON.parse(window.localStorage.getItem('sampleList')));    
};

cookie数据会自动在web浏览器和web服务器之间传输的。
name,value,path,domain,max-age
如果没有为一个cookie设置域属性,那么domain属性的默认值是当前web服务器的主机名。cookie的域只能设置为当前服务器的域。
secure为true是,只能通过https或者其他安全的协议连接的时候传递cookie。
保存cookie,name=value;max-age=seconds;path=path;domain=domain;secure
要改变cookie的值,需要使用相同的名字、路径和域,但是新的值重新设置cookie的值。
要删除一个cookie,需要使用相同的名字、路径和域,然后指定一个任意(非空)的值,并且将max-age属性指定为0,再次设置cookie。
单个cookie大小有4KB的限制。每个web服务器存储不超过20个cookie,浏览器存储不超过300个cookie

window.document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)')

manifest文件

CACHE MANIFEST
#下面的内容是应用程序依赖的资源文件的URL
CACHE:
myapp.html
myapp.js

#清单每行包含两个URL
FALLBACK:
vidoes/ offline_help.html

#URL中的资源从不缓存,总要通过网络获取
NETWORK:
cgi/

应用程序缓存清单文件约定以.appcache作为文件扩展名。

缓存的更新
浏览器只检查清单文件,而不会去检查缓存的文件是否有更新。
浏览器在更新缓存过程中会触发一系列事件,可以通过注册处理程序来跟踪这个过程同时提供反馈给用户。
该事件处理程序是注册在ApplicationCache对象上,该对象是Window的applicationCache属性的值。
checking——noupdate(downloading更新或者首次下载)——progress——updateready(cached)
——error(离线状态)
——obsolete(引用一个不存在的清单文件,应用将被从缓存中移除)
update()
swapCache()


crystal
9 声望1 粉丝