Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's default value of cache-control?

My problem is: sometimes browser over-cached some resources even if i've already modified them. But After F5, everything is fine.

I studied this case whole afternoon. Now i completely understood the point of "Last-Modified" or "Cache-Control". And i know how to solve my issue (just .js?version or explicit max-age=xxxx). But the problem is still unsolved: how does browser handle the response header without "Cache-Control" like this:

Content-Length: 49675 Content-Type: text/html Last-Modified: Thu, 27 Dec 2012 03:03:50 GMT Accept-Ranges: bytes Etag: "0af7fcbdee3cd1:972" Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Date: Thu, 24 Jan 2013 07:46:16 GMT  

They clearly cache them when "Enter in the bar"

enter image description here

like image 267
rhapsodyn Avatar asked Jan 24 '13 08:01

rhapsodyn


People also ask

Is Cache-Control public by default?

The max-age directive on a response implies that the response is cacheable (i.e., "public") unless some other, more restrictive cache directive is also present.

Where do I set Cache-Control?

To use Cache-Control headers, choose Content Management | Cache Control Directives in the administration server. Then, using the Resource Picker, choose the directory where you want to set the headers. After setting the headers, click 'OK'.

What is Cache-Control Unit?

Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).

What is Max-age Cache-Control?

Cache-control: max-age It is the maximum amount of time specified in the number of seconds. For example, max-age=90 means that a HTTP response remains in the browser as a cached copy for the next 90 seconds before it can be available for reuse.


2 Answers

RFC 7234 details what browsers and proxies should do by default:

Although caching is an entirely OPTIONAL feature of HTTP, it can be assumed that reusing a cached response is desirable and that such reuse is the default behavior when no requirement or local configuration prevents it. Therefore, HTTP cache requirements are focused on preventing a cache from either storing a non-reusable response or reusing a stored response inappropriately, rather than mandating that caches always store and reuse particular responses.

like image 167
SilverlightFox Avatar answered Sep 17 '22 21:09

SilverlightFox


Caching is usually enabled by default in browers, so cache-control can be used to either customise this behaviour or disable it.

Although caching is an entirely OPTIONAL feature of HTTP, it can be assumed that reusing a cached response is desirable and that such reuse is the default behavior when no requirement or local configuration prevents it. Therefore, HTTP cache requirements are focused on preventing a cache from either storing a non-reusable response or reusing a stored response inappropriately, rather than mandating that caches always store and reuse particular responses. [https://www.rfc-editor.org/rfc/rfc7234#section-2]

The time the browser considers a cached response fresh is usually relative to when it was last modified:

Since origin servers do not always provide explicit expiration times, a cache MAY assign a heuristic expiration time when an explicit time is not specified, employing algorithms that use other header field values (such as the Last-Modified time)... If the response has a Last-Modified header field (Section 2.2 of [RFC7232]), caches are encouraged to use a heuristic expiration value that is no more than some fraction of the interval since that time. A typical setting of this fraction might be 10%. [https://www.rfc-editor.org/rfc/rfc7234#section-4.2.2]

This post has details of how the different browsers calculate that value.

like image 32
Jon Avatar answered Sep 18 '22 21:09

Jon