2014-05-07 99 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; 
}; 
相关问题