cache control vs expires headers & if modified since
Cache control headers directives Meaning
http cache-control header examples Best practices for html & js Css
Html
cache-control no-cache no-store
nginx
Add_header cache-control “no-cache, no-store”;
add_header Cache-Control “s-maxage=864000, max-age=0”;
CDN Server ache validity and browser cache validity 0 seconds means no store.
for html it needs sere from the server. (because no user can read same html page with same content multiple times, even if you updated browser or proxy /cdn seres old page because its expiry set to high.)
2nd reason: browser cache storage space & its validity on users local hard disk. ( most browsers overrides the data if cache limits the space / storage).
Firefox has option to maximum browser cache space, 1GB. chrome it automatically uses available space.
for CSS .JS. Image you can set upto maximum 1 year.
Add cache control header htaccess apache
Header set Cache-Control “max-age=31536000, public”
</filesMatch>
Add cache control header in Nginx
location block for static
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires max;
}
Cache control header for html files
etag on;
add_header Vary “Accept-Encoding, Cookie”;
add_header Cache-Control “no-cache, no-store, must-revalidate”;}
Last-Modified header
Remove Expires: Thu, 19 Nov 1981 PHP Header Nginx, Apache, Whatever with root Access
1 year = 525600 minutes
session.cache_expire = 525600