有没有一种方法可以使用JavaScript将文件添加到HTML5应用缓存中?

4
有没有一种方法可以使用JavaScript动态注入文件到applicationCache中?我看到了一些关于applicationCache.add()函数的参考,但是我在使用Chrome进行测试时找不到任何文档,并且它也不存在于window.applicationCache对象中。
我正在开发一个Web应用程序,根据决策需要将文件注入到applicationCache中。不幸的是,这个应用程序没有传统的服务器端组件(基本上是静态文件和JS与数据源通信),因此我不能像使用PHP那样创建动态清单文件。
有没有办法做到这一点?
谢谢!

你可以使用 localStorage 来存储文件内容,然后使用 Data URIs 从中作为资源调用。 - CBroe
1
你所听说的 add() 方法根本不是 HTML5 离线应用规范的一部分。看起来它是 Firefox 中 Chrome 引擎使用的内部方法 - Epoc
1个回答

1
正如您下面所看到的,不存在applicationCache.add()函数,您只能更新您的清单,因此使缓存无效。

参考

[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;
};

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接