5
votes

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?

2
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? - Stoive
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. - SAHbKA
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. - robertc
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. - SAHbKA
Ahh, there's your problem... you're giving the user a different web app every time. - Stoive

2 Answers

7
votes

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.

0
votes

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.