为什么离线Web应用程序不起作用? [英] Why offline web application doesn't work?
问题描述
大多数浏览器都支持离线应用。
我复制了 WHATWG < a>并将其放在网络服务器上,但是当我按照以下步骤进行测试时它无效:
It looks like offline app is supported on most browsers. I copied the example app from WHATWG and put it on an web server but it didn't work when I test with the steps below:
- 浏览到clock.html使用Windows Phone 8.1(IE 11)
- 页面看起来不错,然后退出浏览器
- 禁用wifi和单元格数据
- 再次浏览到clock.html但获取
无法找到服务器或DNS错误
- browse to clock.html with windows phone 8.1 (IE 11)
- page looks fine, then exit the browser
- disable wifi and cell data
- browse to the clock.html again but get
Cannot find server or DNS error
我没有在私人模式下浏览,也没有清除任何浏览器缓存。我不知道这是否特定于Windows手机,但稍后会测试其他设备。
I was not browsing in private mode and did not clear any browser cache. I don't know if this is specific to windows phone yet, but will test with other devices later.
clock.appcache
clock.appcache
CACHE MANIFEST
CACHE:
clock.html
clock.css
clock.js
clock.html
clock.html
<!DOCTYPE html>
<html manifest="clock.appcache">
<head>
<title>Clock</title>
<script src="clock.js"></script>
<link rel="stylesheet" href="clock.css">
</head>
<body onload="updateIndicator()" ononline="updateIndicator()" onoffline="updateIndicator()">
<div>The network is: <span id="indicator">(state unknown)</span></div>
<div>The time is: <span id="clock"></span></div>
</body>
</html>
clock.css
clock.css
.clock { font: 2em sans-serif; }
clock.js
setInterval(function () {
document.getElementById('clock').innerHTML = new Date();
}, 1000);
function updateIndicator() {
document.getElementById('indicator').innerHTML = navigator.onLine ? 'online' : 'offline';
}
推荐答案
clock.appcache需要使用正确的mime类型 text / cache-manifest
。大多数服务器默认不这样做。您需要使用正确的设置修改web.config或.htaccess。
The clock.appcache needs to served with the correct mime type of text/cache-manifest
. Most servers don't do this by default. You will need to modify the web.config or .htaccess with the correct setting.
IIS https://stackoverflow.com/a/7118481/195050
Apache https://stackoverflow.com/a/3281574/195050
这篇关于为什么离线Web应用程序不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!