2

How long will cached CSS file get updated in browser if I don't do anything specifically?

I googled this but haven't found a clear answer. I know I can use file.css?v=1 to force the browser to load the updated version or I can use hard reload feature of the browser. But what if I don't do all of these? So far the browser will always load the cached old version.

Without hard reload and any other setup in server, how long will a local browser update the cached CSS file? Will the cached version stay there forever? (unless the cache space is full to make space).

halfer
  • 19,824
  • 17
  • 99
  • 186
sgon00
  • 4,879
  • 1
  • 43
  • 59
  • Possible duplicate of [What's default value of cache-control?](https://stackoverflow.com/questions/14496694/whats-default-value-of-cache-control) – Alexei Levenkov Jan 25 '19 at 02:59
  • @AlexeiLevenkov thanks a lot for the quick reply. I think it's related, but not duplicated. That question's focus is the value of cache-control. My focus is the browser's behavior. I think a browser does not have to follow cache-control. Chrome, Safari, IE/edge, firefox or opera may have different decision on how to handle cached css file. Thanks. – sgon00 Jan 25 '19 at 03:02

1 Answers1

1

Browsers generally follow the IETF spec for HTTP caching. This was introduced in the HTTP 1.1 spec. But they do all vary if the content being served doesn't use an HTTP Cache-Control header. Ultimately you can't rely on the hope that your updated file will be loaded by the client unless you either use a URL cache-buster, as you mentioned, or serve your content with proper cache-control headers.

Community
  • 1
  • 1
  • 3
    Thanks a lot for the answer. But I really want to know what browsers do these days. For example, how long will chrome browser to update its cache? Will it keep the old cached file forever? or 2 days, 3 days or more? Thanks a lot. – sgon00 Jan 25 '19 at 03:27