1

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???

Srini
  • 348
  • 1
  • 2
  • 17

2 Answers2

0

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.

Mike Nitchie
  • 1,166
  • 2
  • 13
  • 29
  • As this requirement is for single page application, reloading complete page to remove the appcache is not feasible option. If I am hitting any service, based on server response appcache needs to be cleared using javascript without reloading page. – Srini Jun 15 '15 at 18:13
0

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.

Srini
  • 348
  • 1
  • 2
  • 17