2014-05-07 100 views
4

有沒有辦法使用JavaScript動態地將文件注入到applicationCache中?我看到了一些對applicationCache.add()函數的引用,但我找不到任何文檔,並且在我使用Chrome進行測試時,它不存在於window.applicationCache對象上。有沒有辦法使用JavaScript將文件添加到HTML5 applicationCache?

我有一個基於決定需要將文件注入到applicationCache的Web應用程序。不幸的是,這個應用程序沒有傳統的服務器端組件(它基本上是靜態文件和與數據源通信的JS),所以我不能只使用類似PHP的東西來創建動態清單文件。

有沒有辦法做到這一點?

謝謝!

+0

你可以使用',而不是localStorage'存儲文件內容,然後使用它們作爲資源從那裏使用數據URI。 – CBroe

+1

您所聽到的'add()'方法根本不屬於HTML5脫機應用程序規範。它似乎是Firefox中Chrome引擎使用的[內部方法](https://developer.mozilla.org/en-US/docs/nsIDOMOfflineResourceList#add.28.29)。 – Epoc

回答

1

你怎麼可以閱讀下面的,不存在的applicationCache.add()功能,你只能更新您的清單,所以緩存失效

reference

[Exposed=Window,SharedWorker] 
interface ApplicationCache : EventTarget { 

    // update status 
    const unsigned short UNCACHED = 0; 
    const unsigned short IDLE = 1; 
    const unsigned short CHECKING = 2; 
    const unsigned short DOWNLOADING = 3; 
    const unsigned short UPDATEREADY = 4; 
    const unsigned short OBSOLETE = 5; 
    readonly attribute unsigned short status; 

    // updates 
    void update(); 
    void abort(); 
    void swapCache(); 

    // events 
      attribute EventHandler onchecking; 
      attribute EventHandler onerror; 
      attribute EventHandler onnoupdate; 
      attribute EventHandler ondownloading; 
      attribute EventHandler onprogress; 
      attribute EventHandler onupdateready; 
      attribute EventHandler oncached; 
      attribute EventHandler onobsolete; 
}; 
相關問題