Reputation: 21
STEPS TO REPRODUCE THE PROBLEM:
Step 1: Let´s say you have cleaned up your cache history on your browser (firefox).
Step 2: You type www.stackoverflow.com on your browser to could get some new data on your cache folder.
Step 3: you type on your browser "cache:about"
Step 4: you click on "Disk cache device/List cache entries"
Step 5: I search for some ".png" file that has been downloaded to my cache folder. And taking notice that the data size is actually 16425bytes.
Step 6: Copy the path where the image has been stored on your computer.
Step 7: I take a fast look how the image looks like by clicking on this link before I continue with the problematic issue.
Step 8: Checking image
Step 9: Start/run/ and pasting the path we have copied recently, where the image has been stored on your system.
Step 10: Here is the image! But we have to type manually ".png"
Step 11: I take a look how it looks like:
Step 12: I edit the image I want to change the size of the file and have another size than the real one that the browser cached. So I make the image smaller and save it.
Step 13: I check so the size of the file have really changed. before was 17kb now 3kb.
Step 14: I remove the ".png" text i added to the file name so the browser can read it
Step 15: Now I press reload on my browser and the file don´t gets readed!
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
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
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