No static file is cached

I have set up CloudFlare for my website http://www.funfun.org.cn, the caching level is Standard and The development mode is Disabled.

By loading the home page http://www.funfun.org.cn/1/#/home, I can see Server: cloudflare in the response header. But it seems that all the static JS files have CF-Cache-Status:MISS in their response header.

Does anyone know why?

Edit 1: I also see Cache-Control:no-cache in the request header. How could we modify this?

enter image description here

Answer

The problem, as you say, is likely the “no cache” directive. Have a look at my tutorial which goes through setting up Nginx and CloudFlare.

The key parts for you are using Nginx to set caching headers. You’ll need Nginx to have the “headers more” module included – “nginx -V” will tell you if it was compiled in. Some distributions include this, otherwise you’ll have to build Nginx yourself, which is pretty straightforward (if you Google it there will be many many articles, including the Nginx website).

The following clears the existing headers

more_clear_headers "Pragma"; more_clear_headers Server; more_clear_headers "Expires";

Then we can set the header manually. For image we use quite a long expires time

add_header Cache-Control "public, max-age=691200, s-maxage=691200";

For pages we keep it shorter – many sites will need this much shorter or even set to no caching

add_header Cache-Control "public, max-age=86400, s-maxage=86400";

Attribution
Source : Link , Question Author : Tie , Answer Author : Tim

Leave a Comment