Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudflare does not cache static assets with proper headers

Tags:

cloudflare

I've read in the docs that cloudflare caches js and css files. (https://support.cloudflare.com/hc/en-us/articles/200172516-Which-file-extensions-does-Cloudflare-cache-for-static-content-)

But in my case the header cf-cache-status has the value MISS.

One example would be a css reasources like this:

https://example.com/style.a574b.css

with the following response headers:

cache-control: public, max-age=31536000
cf-cache-status: MISS
cf-ray: 405badb4ec2297bc-FRA
content-encoding: br
content-type: text/css
date: Tue, 03 Apr 2018 12:53:31 GMT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
expires: Wed, 03 Apr 2019 12:53:31 GMT
last-modified: Tue, 03 Apr 2018 01:14:20 GMT
pragma: 
server: cloudflare
status: 200
vary: Accept-Encoding
via: 1.1 vegur
x-application-context: ourder:prod,heroku:3829
x-content-type-options: nosniff
x-xss-protection: 1; mode=block

The original response (without cloudflare between is:)

 Accept-Ranges: bytes
 Cache-Control: max-age=31536000, public
 Content-Encoding: gzip
 Content-Length: 948
 Content-Type: text/css
 Date: Tue, 03 Apr 2018 19:17:46 GMT
 Expires: 
 Last-Modified: Tue, 03 Apr 2018 13:19:21 GMT
 Pragma: 
 Server: Cowboy
 Via: 1.1 vegur
 X-Application-Context: ourder:prod,heroku:20249
 X-Content-Type-Options: nosniff
 X-Xss-Protection: 1; mode=block
like image 773
Simon Ludwig Avatar asked Apr 03 '18 19:04

Simon Ludwig


People also ask

Does Cloudflare cache response headers?

Note that Cloudflare does cache the resource even if there is no Cache-Control header based on status codes.

Does Cloudflare do caching?

Cloudflare makes customer websites faster by storing a copy of the website's content on the servers of our globally distributed data centers. Content can be either static or dynamic: static content is “cacheable” or eligible for caching, and dynamic content is “uncacheable” or ineligible for caching.

Does Cloudflare automatically cache images?

Requests proxied through Cloudflare are cached even without Workers according to a zone's default or configured behavior (for example, static assets like files ending in . jpg are cached by default).


1 Answers

With the Cloudflare Support Help i was able to solve the problem. The empty Expires Header causes the problem.

See this ticket for more details: https://support.cloudflare.com/hc/en-us/requests/1508118?page=1

like image 183
Simon Ludwig Avatar answered Nov 15 '22 18:11

Simon Ludwig