Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

233.[HTML5]HTML5的离线储存怎么使用,工作原理能不能解释一下? #233

Open
webVueBlog opened this issue May 20, 2020 · 1 comment
Labels
html5 html5

Comments

@webVueBlog
Copy link
Member

No description provided.

@webVueBlog webVueBlog added the html5 html5 label May 20, 2020
@webVueBlog
Copy link
Member Author

在用户没有与因特网连接时,可以正常访问站点或应用,在用户与因特网连接时,更新用户机器上的缓存文件

原理:HTML5的离线存储是基于一个新建的.appcache文件的缓存机制(不是存储技术),通过这个文件上的解析清单离线存储资源,这些资源就会像cookie一样被存储了下来。之后当网络在处于离线状态下时,浏览器会通过被离线存储的数据进行页面展示

如何使用:

页面头部像下面一样加入一个manifest的属性;
在cache.manifest文件的编写离线存储的资源
在离线状态时,操作window.applicationCache进行需求实现

CACHE MANIFEST
#v0.11
CACHE:
js/app.js
css/style.css
NETWORK:
resourse/logo.png
FALLBACK:
/offline.html

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
html5 html5
Projects
None yet
Development

No branches or pull requests

1 participant