首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当互联网联机时HTML5不缓存

当互联网联机时HTML5不缓存
EN

Stack Overflow用户
提问于 2016-12-20 05:30:47
回答 1查看 38关注 0票数 0

在这里,我计划构建一个HTML5移动应用程序,它具有离线阅读机制。

我有一些动态的内容,在一个网页,我需要在两个显示时,互联网是否存在。

我正在使用缓存机制,由清单提供。

当我第一次在网上加载动态页面时,它被缓存,当我在互联网上离线时,我也能看到动态页面。

但问题是,当互联网连接再次恢复时,是否应该再次调用动态页面?但这是不可能的。

我试图为mozilla放置一个.htaccess文件,火狐在这个博客http://html5doctor.com/go-offline-with-application-cache/中说

代码语言:javascript
复制
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>

为此,我为ex:- https://www.sitepoint.com/common-pitfalls-avoid-using-html5-application-cache/浏览了许多博客和站点。

什么都没发生!

我的网页是:

1) home.html

代码语言:javascript
复制
<!DOCTYPE html>
<html manifest="dtt.appcache">
<body>

<p><button onClick="loadDoc(1)" type="button">home</button> || <button onClick="loadDoc(2)" type="button">centers</button> || <button onClick="loadDoc(3)" type="button">about us</button></p>

<!--<p><a href="home.html" >home</a> || <a href="centers.php" >centers</a> || <a href="about-us.html" >about us</a></p>-->

<div id="contentarea">
This is my home page.
</div>

 <script>

    function loadDoc(id) {

    var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          document.getElementById("contentarea").innerHTML =
          this.responseText;
        }
      };

    if(id == '1'){
         document.getElementById("contentarea").innerHTML =
          'This is my home page'
    } else if(id=='2'){


      xhttp.open("GET", "centers.php", true);
      xhttp.send();
  }else if(id=='3'){
  document.getElementById("contentarea").innerHTML =
          'This is my about us page'
  }
}
 </script>
</body>
</html>

2) centers.php

代码语言:javascript
复制
<!DOCTYPE html>
<html manifest="dtt.appcache">
<body>
<?php echo time().'<br>';?>
</body>
</html>

3) dtt.appcache

代码语言:javascript
复制
CACHE MANIFEST
# 2003-12-01 v2.0.0
home.html
centers.php
about-us.html

我的要求很简单,就好像有互联网连接一样,页面应该缓存为离线阅读(这种情况正在发生),如果每次从动态内容页面读取互联网连接都存在。

EN

回答 1

Stack Overflow用户

发布于 2016-12-20 05:39:08

实际上,应用程序缓存特性现在是废弃的。所以大多数浏览器都不能完全支持。相反,您可以使用缓存存储特性,使用服务工作者。它也支持chrome浏览器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41235490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档