How long are files usually kept in a browser's cache

Browser Cache

Browser Cache Problem Overview


How long are files usually kept in a browser's cache? I'm wondering about the general population - how long would I need to wait to be reasonable certain that most people's caches will refetch the file?

Browser Cache Solutions


Solution 1 - Browser Cache

It depends much on person, browser and settings.

Browsers usually reserve a certain amount of disk space, like 12 MiB, to this task. If a user stops using the browser it is indefinitely. If he/she uses the browser rarely, it will be until the expiration - either by internal policy or by HTTP headers. If he/she uses the browser heavily, it can be 12 minutes or even less.

I believe that it is hard to say 'in general' as I had a website on which 50% entries were from Firefox and 49% from Opera when IE at that point had over 75% market share. If the target audience of your site are users who use their browsers heavily, it can be very short. On the other hand if your site is only website visited it can be nearly never.

Solution 2 - Browser Cache

Typically files will stay in the cache until space runs out. There is an article that describes some of the defaults for popular browsers: It's Time to Rethink the Default Cache Size of Web Browsers

As Maciej stated, it's also a matter of how much each person browses. Think of the user base that will be visiting your site into consideration, as well as how bandwidth-heavy your site is (if the average user downloads tons of content from your site, chances are they will fill their cache real fast).

If a cache refresh is needed, you can force the page to not cache files.

Solution 3 - Browser Cache

As the other answers have stated, it depends upon the browser settings. But note that having a file cached doesn't necessarily mean that changes are not fetched from your site. If configured to do so, the browser will send a request to the server, with details about the date of the cache file. The server than then respond with "ok, use your cache - it's the latest version" when there are no changes. This repsonse is small and quickly sent. If the server version has been updated, then the server will respond with the new version.

How often the browser sends a request to the server is browser-specific - they can be configured to check for updates each time, once an hour, once a day, never or anywhere in between. The server can also specify how often the browser should check for updates.

this is just a sketch - it is simplified and incomplete. For the complete details, see W3C - HTTP/1.1 Caching.

Solution 4 - Browser Cache

Depends on how long the server specifies. The server sends back parameters in response header. They can specify max-age (how long to cache the file before it expires in milliseconds) or an expiration date (date that the file will expire). If it has both, max-age will take priority.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionB TView Question on Stackoverflow
Solution 1 - Browser CacheMaciej PiechotkaView Answer on Stackoverflow
Solution 2 - Browser CachephaxianView Answer on Stackoverflow
Solution 3 - Browser CachemdmaView Answer on Stackoverflow
Solution 4 - Browser CacheGuy MoritaView Answer on Stackoverflow