离线appcache无法正常工作

时间:2012-07-06 19:08:36

标签: html5 caching web-applications offline

为什么我的离线应用没有被任何浏览器缓存?

我在这里创建了一个简化的测试:http://design.aqueo.us/test/appcache/

它只有两个文件:一个html文件加上清单。 (html文件包含一些javascript来显示缓存状态。)检查控制台日志,你会看到它总是显示“缓存状态:未缓存”。此外,chrome:// appcache-internals /(在谷歌浏览器中)不会列出该网站。据我所知,浏览器甚至从不提取清单文件。我在多个浏览器中尝试过这个。

这是清单:

CACHE MANIFEST
# .

这是HTML:

<!doctype html>
<html>
<head manifest="offline.appcache">
    <meta charset="utf-8">
    <title>Appcache test</title>
<script>
(function() {
    var webappCache = window.applicationCache;

    function loaded()
    {
        var h1El = document.querySelector("h1");
        var connectionStatus = ((navigator.onLine) ? 'online' : 'offline');
        h1El.textContent = h1El.textContent + " - currently: " + connectionStatus;

        switch(webappCache.status)
        {
            case 0:
                console.log("Cache status: Uncached");
                break;
            case 1:
                console.log("Cache status: Idle");
                break;
            case 2:
                console.log("Cache status: Checking");
                break;
            case 3:
                console.log("Cache status: Downloading");
                break;
            case 4:
                console.log("Cache status: Updateready");
                break;
            case 5:
                console.log("Cache status: Obsolete");
                break;
        }

    }

    function updateCache()
    {
        webappCache.swapCache();
        console.log("Cache has been updated due to a change found in the manifest");
    }

    function errorCache()
    {
        console.log("You're either offline or something has gone horribly wrong.");
    }

    window.addEventListener("load", loaded, false);
    webappCache.addEventListener("updateready", updateCache, false);
    webappCache.addEventListener("error", errorCache, false);

})();
</script>
</head>
<body>
    <h1>Appcache Test</h1>
</body>
</html>

1 个答案:

答案 0 :(得分:9)

难以置信!在完成所有调试和拔出之后,我在HEAD元素上使用了manifest属性而不是HTML元素!在所有愚蠢的错误中!

有问题的链接现在按预期工作。

更新:为了明白这一点,HTML文件的顶部应该是这样的:

<!doctype html>
<html manifest="offline.appcache">
<head>
相关问题