2

For years I have appended a querystring to the end of my CSS whenever I made a change that needed to proliferate to client machines:

<link href="/Resources/styles/styles.css?v=1" rel="stylesheet" />

However, I have noticed lately that Chrome seems to be pretty "smart" about knowing when I have changed the CSS files and often the latest CSS shows up in testing without needing the querystring trick.

So I was wondering: have the modern browsers incorporated new logic to make the querystring trick unnecessary?

Thanks!

Matt Cashatt
  • 23,490
  • 28
  • 78
  • 111
  • I've vaguely noticed this, but I've still had times where something annoyingly doesn't update with out a hard refresh – Andrew Barber Aug 02 '14 at 20:07
  • I tested this fairly thoroughly in Chrome about 18 months ago - http://stackoverflow.com/a/3870743/453277. If you find that behavior in Chrome has changed from what I wrote, please leave a comment on my answer so I can update it. – Tim M. Aug 02 '14 at 20:26
  • Perhaps something changed in the HTTP headers for caching the resource. – Kwebble Aug 02 '14 at 20:58

1 Answers1

1

The trick isn't obsolete as browsers still have no way of knowing the file has been modified without requesting it, this is just a simple limitation of HTTP. Chrome might be able to guess that your CSS has changed if the markup has changed and it no longer seems to match, but I'm not too sure how this might be happening.

David Carpenter
  • 1,389
  • 2
  • 16
  • 29
  • I am guessing that browsers can tell by, for example, comparing time stamps on local copies vs server copies. I am just wondering if they are doing something like that. – Matt Cashatt Aug 02 '14 at 20:10
  • They do use the HTTP response code (200 and 304 being the most important ones here), but there isn't any way for the browser to identify a difference in timestamp or response code without first making the request. If you look at the headers for your page request, you won't see any information about whether or not the corresponding CSS files have changed. The only way a browser can know for sure that the file has changed is to submit a request, otherwise it must be making some kind of educated guess. – David Carpenter Aug 02 '14 at 20:17