2012-07-06 106 views
2

爲什麼我的離線應用沒有被任何瀏覽器緩存?離線appcache無法正常工作

我已經在這裏創造一個簡單的測試:http://design.aqueo.us/test/appcache/

只有兩個文件:一個HTML文件加上清單。 (該html文件包含一些JavaScript來顯示緩存狀態。)檢查控制檯日誌,您會看到它始終顯示「緩存狀態:未緩存」。另外chrome:// appcache-internals /(在Google Chrome中)不會列出該網站。據我所知,瀏覽器甚至不會提取清單文件。我已經在多個瀏覽器中嘗試了這一點。

這裏的清單:

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> 

回答

8

難以置信!在完成所有的調試和頭髮拉出之後,我在HEAD元素上顯示了manifest屬性,而不是HTML元素!所有的愚蠢的錯誤!

有問題的鏈接現在按預期工作。

更新:只是爲了讓事情很明顯,這裏是HTML文件的頂部應該是什麼樣子:

<!doctype html> 
<html manifest="offline.appcache"> 
<head> 
+1

哦。我的。 Goooddddd!我覺得自己像個白癡,因爲我只是在過去的一個小時裏爲此工作。 – Sirens 2014-09-04 01:17:05