简体   繁体   中英

HTML5 appcache remove programmatically

Is there any option to remove HTML5 appcache using javascript?

These are available option for removing/disabling appcache:

  1. Update Manifest file with empty content - existing appcache is available without any resource
  2. Include dummy url in existing manifest file - It will throw 404 for new appcache. But old appcache is not completely remove from browser engine
  3. Remove from chrome developer console - If we want to remove manually.

But My requirement is to remove appcache programmatically using javascript based on notification from server. 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. Otherwise, return a different html page based on the value of that flag that simply does not include the manifest attribute.

When you get your notification from the server, refresh that page with ?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?

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:

NETWORK:
*

I find this to be an excellent resource.

I found out the solution by utilizing Obsolete event in AppCache API.

Appcache download only with version update:

When appcache version is getting modified, new files will start to download. Till that time, application doesn't wait to block the application launch. It works by using existing cached files (CSS, JS and action files). But newly downloaded static files (CSS, JS) will be executed only on relaunch.

Appcache download with obsolete event:

Instead of updating appcache version, we can create new appcache files and same reference has been added into HTML file. Whenever appcache file status is coming as 404 or 410, it will return obsolete event. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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