html5 manifest 离线应用程序

1)配置IIS服务器

进入IIS,找到需要配置的网站,如下界面


双击HTTP相应标头,添加【名称】【值】分别是【.manifest】【text/cache-manifest】,进入如下界面


代码实现

创建index.css、index.html、index.js、index.manifest

index.css

span {
    font-size:20px;
}
index.js

function pageLoad() {
    if (navigator.onLine) {
        alert('当前在线');
        window.applicationCache.addEventListener('checking', function () {
            console.log('正在检测是否有更新...');
        }, true);
        window.applicationCache.addEventListener('downloading', function () {
            console.log('正在下载可用的缓存...');
        }, true);
        window.applicationCache.addEventListener('noupdate', function () {
            console.log('没有最新的缓存更新!');
        }, true);
        window.applicationCache.addEventListener('progress', function () {
            console.log('本地缓存正在更新中...');
        }, true);
        window.applicationCache.addEventListener('updateready', function () {
            console.log('本地缓存已更新成功!');
            alert('刷新页面获取最新版本!');
        }, true);
        window.applicationCache.addEventListener('error', function () {
            console.log('本地缓存更新时出错!');
        }, true);
    } else {
        alert('当前离线');
    }
}

index.manifest

CACHE MANIFEST
#version 0.0.71
CACHE:
index.js
index.css

index.html

<!doctype html>
<html manifest="index.manifest">
<head>
    <title>index</title>
    <link href="index.css" rel="stylesheet" />
    <script src="index.js"></script>
</head>
<body οnlοad="pageLoad();">
    <div>
        <span>Hello World71!</span>
    </div>
</body>
</html>

验证效果

将<span>Hello World71!</span>修改成<span>Hello World72!</span>

界面显示效果如下,没有获取到更新,还是读取的本地缓存数据


修改index.manifest

将#version 0.0.71 修改成#version 0.0.72

查看效果,从服务器获取最新版本,刷新页面界面效果更新了



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值