什么是html5应用程序缓存

经常听说缓存缓存 却不知道缓存究竟是怎么回事?
今天要说的缓存就是指没有网络连接时也可以进行访问
应用程序缓存带来的好处是什么呢?

  1. 离线浏览 用户可以在应用离线时使用它 例如现在的电视剧 不都是先缓起来然后在没网的时候还可以看电视一样的道理吧
  2. 速度 已经缓存的资源加载的更快
  3. 减少服务器负载 浏览器只从服务器下载更新过或更改过的资源
  4. 所有主流浏览器均支持应用程序缓存 除了internet Explorer
  5. 下面举例说明
    首先在demo.html文件中写上如下代码
<!DOCTYPE html>
<html lang="en" manifest="demo.appcahe" >
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>demo</title>
</head>
<body>
    <img src="./w3c.gif" width='500' height='600' alt="">
</body>
</html>

然后在manifest对应的文件demo.appcahe中编写离线存储的资源

CACHE MANIFEST
# 需要缓存的列表
CACHE
w3c.gif
#不需要缓存的
NETWORK
*
FALLBACK
#访问缓存失败后,备用访问的资源,第一个是访问源 第二个是替换文件*.html / offline.html
/demo/ /404.html
发布了30 篇原创文章 · 获赞 9 · 访问量 2499

猜你喜欢

转载自blog.csdn.net/weixin_42446516/article/details/98484294
今日推荐