Alice
Alice

Reputation: 21

How to edit data size on the cache file using Firefox or Chrome?

STEPS TO REPRODUCE THE PROBLEM:

EXPECTED RESULT: - On the example to make it simple to understand I used a ".png" but you don´t get the same result. On my real issue amb trying to make the cache read a FLASH .swf file that I hade change it activly the original data size.. Any ideas? links? I can´t find info on internet about how to say to the browser to read again the file that has been downloaded, even if the size has changed!!

Upvotes: 2

Views: 1905

Answers (2)

Pragy Agarwal
Pragy Agarwal

Reputation: 579

i was facing the same problem, finally got a work around, thanks to this thread.

this is for firefox only. goto about:config edit the variable "browser.cache.check_doc_frequency" (default 3) to 2 (http://kb.mozillazine.org/Browser.cache.check_doc_frequency)

edit the file in the cache directory. (doesn't matter if the new size is different!) no need to change the file size entries in chache_001.

hope this helps you.

Edit: just make sure you keep the file size less than the original one for swf files.

Reason: I don't really know, but when I tried editing a swf for an online game, the game could no longer load with the new cache file (like firefox reserves x memory bytes for the thing, x was specified by the server .. but the file is larger than x bytes, so the whole file will not be loaded, and the flash movie wont load).

I edited some of the images in the swf to blank images of the same size, recompiled and recompressed to get a filesize lower than that of the original swf, and it worked!

Upvotes: 0

mathtutor
mathtutor

Reputation: 53

The point is that client will never check the server again if it is cached, until (and if) the cache has expired for that element. Set a max age on the HTTP header to 10 minutes say, for client to redownload it if it has been more than 10 mins since last downloaded. You cannot update just because size changed. Unless you have a JS or ajax or something that will update the client cache based on some result that is retrieved when the client checks the server to see if there was a recent change, other that it is impossible.

So if you have to have it, you will have to keep track on the server if something changes, based on existing data on the server. For instance, server keeps track of the initial size. If you change the image size (or suppose something in your web application changes it), the server will know that this has been changed on the server (because it will always get the current image size too on the server). So then you also need to keep track of the image size on the client when the image is downloaded, with either a cookie or with html5 localStorage.

So then the client part of your script requests the server on page load (sending the image size too that is stored in cookie or localStorage) and the server script will then compare the size of current image with the size sent by the client. If it is different it expires the client cache explicitly which means the client has to redownload the image explicitly. Otherwise it does nothing and just uses the cached image.

So basically you will need to treat your image much like you would a login cookiet(where server explicitly tracks it, expires it, sets new one, expires it, etc.) if you want this kind of functionality.

Upvotes: 1

Related Questions