在这里,我计划构建一个HTML5移动应用程序,它具有离线阅读机制。
我有一些动态的内容,在一个网页,我需要在两个显示时,互联网是否存在。
我正在使用缓存机制,由清单提供。
当我第一次在网上加载动态页面时,它被缓存,当我在互联网上离线时,我也能看到动态页面。
但问题是,当互联网连接再次恢复时,是否应该再次调用动态页面?但这是不可能的。
我试图为mozilla放置一个.htaccess文件,火狐在这个博客http://html5doctor.com/go-offline-with-application-cache/中说
<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
<!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
<!DOCTYPE html>
<html manifest="dtt.appcache">
<body>
<?php echo time().'<br>';?>
</body>
</html>3) dtt.appcache
CACHE MANIFEST
# 2003-12-01 v2.0.0
home.html
centers.php
about-us.html我的要求很简单,就好像有互联网连接一样,页面应该缓存为离线阅读(这种情况正在发生),如果每次从动态内容页面读取互联网连接都存在。
发布于 2016-12-20 05:39:08
实际上,应用程序缓存特性现在是废弃的。所以大多数浏览器都不能完全支持。相反,您可以使用缓存存储特性,使用服务工作者。它也支持chrome浏览器。
https://stackoverflow.com/questions/41235490
复制相似问题