Browser Item Caching and URLs
Posted
by Damon Armstrong
on Simple Talk
See other posts from Simple Talk
or by Damon Armstrong
Published on Mon, 25 Jun 2012 19:18:37 +0000
Indexed on
2012/06/26
9:21 UTC
Read the original article
Hit count: 174
Uncategorized
Ultimately you want the browser to cache things like Flash components, Silverlight XAP files, and images to avoid users having to download them each time they hit a page. But during development it’s very useful to NOT have things cached so you are always looking at the most up-to-date file. You can always turn off caching on your browser, but if you use your browser for daily browsing then its not the greatest option. To avoid caching we would always just slap a randomly generated GUID to the back of the URL of any items we didn’t want to cache (e.g. http://someserver.com/images/image.png?15f073f5-45fc-47b2-993b-fbaa781b926d). It worked well, but you had to remember to remove the random GUID when it went to production.
However, on a GimmalSoft project we recently implemented someone showed me a better way that didn’t need to be removed from production code – just slap the last modified date of the file on the end of the URL (or something generated from the modification date). This was kind of genius approach because it gives you the best of both world. If you modify the file, the browser goes out and gets the newest version. If you don’t modify the file, it has the cached copy. Very helpful! The only down side is that you do have to read the modification date from the file, which does technically take some time.
© Simple Talk or respective owner