Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Does having a query string attached to a URL cause browsers to never cache it? For instance, my site does something like this:

/radar-picture.png?v=sep2013

And it would appear that FireFox never caches that picture; it is downloaded on every request.

I'd like FireFox to cache it, for as long as it wants to. I only want to force it to download when the v= parameter has changed.

share|improve this question
    
I guess you could accomplish this, if you just change the filename itself instead of the query. So now the filename would be radar-picture-sep2013.png and when it changes at some point in the future it would be radar-picture-jan2014.png. You can configure the PNG's max-age to a year so unless the filename changes, the browser can load the cached picture for a long time. –  vstm Sep 11 '13 at 18:07
add comment

2 Answers

This answer on stackoverflow claims that some browsers react differently to hitting enter in the address bar vs clicking on a link when the url has a query string: http://stackoverflow.com/a/85386/1145388

When you are testing, make sure you are clicking on links rather than refreshing or hitting enter in the url bar.

share|improve this answer
1  
I think that answer on stackoverflow may be outdated. When I put a query string on stylesheets style.css?v=sep2013 and the 150KiB background-image:url('bgimage.jpg?v=sep2013');, navigating the site (via clicking links, or typing in address-bar) is very slow in FireFox. –  Mr. Smith Sep 11 '13 at 16:12
add comment

Adding a query-string key/value pair to a static resource (such as an image, CSS or JavaScript) can cause caching issues.

Specifically, since you mentioned Firefox, your issue could be related to a 'Cache collision', where:

The Firefox disk cache hash functions can generate collisions for URLs that differ only slightly, namely only on 8-character boundaries. When resources hash to the same key, only one of the resources is persisted to disk cache; the remaining resources with the same key have to be re-fetched across browser restarts. Thus, if you are using fingerprinting or are otherwise programmatically generating file URLs, to maximize cache hit rate, avoid the Firefox hash collision issue by ensuring that your application generates URLs that differ on more than 8-character boundaries.

[Source: https://developers.google.com/speed/docs/best-practices/caching ]

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.