How to clear Application cache (HTML5 feature) using JavaScript?
Asked Answered
B

2

5

Our Web-Application uses Application cache (cache manifest) to restore HTML page and resources in off-line mode. HTML-pages have sessionIDs as params in URI. So, after each logout and login action new HTML-pages are saved to application cache because sessionId was changed in URI. After some weeks working with application some browsers start work slower. And size of Application cache (tested on FF 3.6+) is about 200Mb! After each logout we clear LocalStorage of browser,but how to clear resources from Application storage?

Bahadur answered 29/4, 2011 at 7:37 Comment(5)
You say 'new HTML-pages are saved to application cache' - this doesn't seem right? A browser handles the application cache as a whole, there is no way to atomically add pages to the application cache. Can you please clarify?Cursory
I use Fallback section of cache manifest in way: mysite.com/?SID=123456&a=1 mysite.com/?SID=123456, So, static pages are downloaded and saved to cache. Each Logout/login generate new sessionId that leads to storing new static pages.Bahadur
Stuff in the application cache shouldn't change every session, what's the point of storing it for offline use if it's going to change? Put static content in the application cache, use local storage and AJAX to load the session specific data so you'll have control over it from JavaScript.Anagrammatize
I understand you point of view but I use dynamic cache manifest file and to get it I add a sessionId to URL of manifest file in <html manifest='?action=getmanifest&sessionId=1234567'> Without sessionId there is no way to get resources and correct result from server. So, as I understood after each generating new session size of cache is getting bigger because of sessionId in dynamic manifest file URI.Bahadur
Ahh, there's your problem... you're giving the user a different web app every time.Cursory
C
7

The problem with the application cache taking up so much space is that you are giving the user agent a different offline web application each time. An offline web application is identified to the user agent by the URI of the cache manifest file, including query string - not the URI of the master file as you might think.

Thus, by including the session ID in the cache manifest URI, you're telling the browser that each session gets its own brand new application without using any of the previously downloaded ones (and thus, never being able to clear them out). You're installing a different web application every time.

Reconsider how you're architecting your application, as currently using HTML5 offline cache manifest is providing no value - just causing excessive downloading. The architecture that web applications encourage is serving all HTML statically, and fetching data that requires sessions via AJAX. Web applications don't work when built in the classic "dynamically generate an HTML page with data on the server" paradigm.

Cursory answered 29/4, 2011 at 12:57 Comment(1)
The problem is fixed by temporary solution: client gets sessionId via cookies and URI to manifest file doesnt include sessionID-as a result the only one ApplicationCache object in browser with static name(without sessionId). @Stoive- sorry, cant add reputation bkz I`m a new user here:)Bahadur
L
0

I'm not sure you do have control over application cache from JavaScript. This is something which should be handled by the browser and the user when clearing the cache.

Lasser answered 29/4, 2011 at 7:46 Comment(3)
The main problem is that users who use our web-Application do not have rights to clear cache from browser using standard methods of browser. The devices(OS,browser) is limited very much and browser Options are restricted for themBahadur
Perhaps the following extension might help ? sites.google.com/site/keigoattic/home/…Lasser
You can manually trigger an update through JavaScript, but that's about it: whatwg.org/specs/web-apps/current-work/multipage/…Cursory

© 2022 - 2024 — McMap. All rights reserved.