简体   繁体   English

HTML5 appcache以编程方式删除

[英]HTML5 appcache remove programmatically

Is there any option to remove HTML5 appcache using javascript? 是否可以使用javascript删除HTML5应用程序缓存?

These are available option for removing/disabling appcache: 这些是用于删除/禁用应用程序缓存的可用选项:

  1. Update Manifest file with empty content - existing appcache is available without any resource 使用空内容更新清单文件-现有appcache可用,没有任何资源
  2. Include dummy url in existing manifest file - It will throw 404 for new appcache. 在现有清单文件中包含虚拟url-它会为新的应用程序缓存抛出404。 But old appcache is not completely remove from browser engine 但是旧的应用程序缓存并未完全从浏览器引擎中删除
  3. Remove from chrome developer console - If we want to remove manually. 从chrome开发者控制台中删除-如果我们要手动删除。

But My requirement is to remove appcache programmatically using javascript based on notification from server. 但是我的要求是根据来自服务器的通知,使用JavaScript以编程方式删除appcache。 Is there any option to achieve this functionality??? 有没有实现此功能的选项???

Perhaps this could work. 也许这可行。 When loading the page from the server, pass a flag indicating whether or not you want the manifest attribute included in the page. 从服务器加载页面时,传递一个标志,指示是否要在页面中包含清单属性。 If you render the html on the server, then pass that flag to whatever templating engine you are using. 如果在服务器上呈现html,则将该标志传递给您使用的任何模板引擎。 Otherwise, return a different html page based on the value of that flag that simply does not include the manifest attribute. 否则,根据该标志的值(不包含manifest属性)返回另一个html页面。

When you get your notification from the server, refresh that page with ?includeAppCache=false . 从服务器收到通知时,请使用?includeAppCache=false刷新该页面。

If this isn't what you are looking for, perhaps I'm mis-understanding you requirements? 如果这不是您要找的东西,也许我误会了您的要求? As I understand your question, the client will receive a notification from the server indicating that the client should no longer use appcache, correct? 据我了解,您的客户端将收到来自服务器的通知,指示客户端不应再使用appcache,对吗?

It is possible that what you are looking for could be done with via appcache events or a different configuration of your manifest file, using the fallback section or a network wildcard such as: 您可以使用fallback部分或网络通配符通过appcache事件或清单文件的其他配置来完成所需的查找,例如:

NETWORK:
*

I find this to be an excellent resource. 我发现是一个很好的资源。

I found out the solution by utilizing Obsolete event in AppCache API. 我通过利用AppCache API中的Obsolete事件找到了解决方案。

Appcache download only with version update: 仅使用版本更新下载Appcache:

When appcache version is getting modified, new files will start to download. 修改appcache版本后,新文件将开始下载。 Till that time, application doesn't wait to block the application launch. 到那时,应用程序将不再等待阻止应用程序启动。 It works by using existing cached files (CSS, JS and action files). 它通过使用现有的缓存文件(CSS,JS和操作文件)来工作。 But newly downloaded static files (CSS, JS) will be executed only on relaunch. 但是新下载的静态文件(CSS,JS)将仅在重新启动时执行。

Appcache download with obsolete event: 具有过时事件的Appcache下载:

Instead of updating appcache version, we can create new appcache files and same reference has been added into HTML file. 无需更新appcache版本,我们可以创建新的appcache文件,并且相同的引用已添加到HTML文件中。 Whenever appcache file status is coming as 404 or 410, it will return obsolete event. 每当appcache文件状态为404或410时,它将返回过时事件。 In this case, if we relaunch the application, new cached files will download parallelly and application will be working with new files download from network instead of loading from old cache. 在这种情况下,如果我们重新启动应用程序,则新的缓存文件将并行下载,并且应用程序将使用从网络下载的新文件,而不是从旧的缓存加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM