javascripthtmlhtml5-appcachecache-manifest

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


Solution

  • 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.