• Home
  • WP tuts
  • Hosting talk
    • Free hosting
    • Cheap Hosting
    • comparison cloud , vps, shared, wordpress
    • managed wordpress hosting
    • managed cloud hosting
  • Speed up wordpress
  • Pc world
  • Services
  • About Me

RAaz Kumar .com

wordpress tutorials seo hosting etc

Cache control Header & expires headers How to set Properly

cache control vs expires headers & if modified since

cache control newer version of expires header.
expires max;
set expiration date to 1984
max expiry date 1 year 365 days 3153600 seconds
Cache-Control: max-age=31536000
304 Not Modified if modified since
(Browser requests to validate the browser cache with server this will done by 304 not modified)
Cache-Control: max-age: 31536000, immutable
immutable not to check server on refresh. een with etag or last modified hash key.
chrome don’t support it, but firefox. Introduced it.
expires header; for older browsers for fallback mechanism.
if modified since helps to provide 304 not modified request when browser requests the server to validate cached resources.
also the googlebot uses it to determine crawl frequency. To reduce load on server by Google bot. example: GoDaddy blocks Googlebot by limiting frequency /rate limiting.
you could see errors in search console.

Cache control headers directives Meaning

Cache-Control: s-maxage=31536000, max-age=86400
s-maxage for CDN & proxies
max-age Remaining for browser.
public  stored by proxy and browser
Private stores only by browser, not cdns/proxy.
no-cache: revalidate cache every time
no-store: don’t store cache browser proxy
no-transform:   don’t rewrite css ex: chrome lite pages
must-revalidate: once cace become stale, has to verify from server.
immutable: explicitly saying don’t need to check server only firefox supports.
max-age=0 equals to no store

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

<filesMatch “.(css|jpg|jpeg|png|gif|js|ico)$”>
Header set Cache-Control “max-age=31536000, public”
</filesMatch>

Add cache control header in Nginx

location block for static

add_header Cache-Control: s-maxage=31536000, max-age=31536000;
location block html/text
add_header  Cache-Control “s-maxage=31536000, max-age=86400”;
//1 hour
location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico)$
{ expires 15d;
add_header Cache-Control max-age=31536000, “public, no-transform”;}
location ~*  \.(text|css|html)$
{    expires 4h;
add_header Cache-Control: s-maxage=31536000, max-age=86400;
}

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires max;
}

Cache control header for html files

wordpress content type html text not ends with .html
add_header  Cache-Control “s-maxage=31536000, max-age=86400”;
location ~ /wp-content/cache/.*html$ {
etag on;
add_header Vary “Accept-Encoding, Cookie”;
add_header Cache-Control “no-cache, no-store, must-revalidate”;}
1 hour for browser 10 hours for proxy /cdn
add_header  Cache-Control “s-maxage=864000, max-age=86400”;
cloudflare respects cache control headers
1 year maximum supported date by protocol.

Last-Modified header

automatically generated by servers like nginx, You can disable by empty add headers. it’s up stream server responsibility to provide last modified time.
like $upstream_cache_status.
use php to add last modified header. through fastcgi.
for files from it will adds last modified time. Ex: css.js

Remove Expires: Thu, 19 Nov 1981 PHP Header Nginx, Apache, Whatever with root Access

1 year = 525600 minutes

 

session.cache_limiter = public, max-age=nocache
session.cache_expire = 180
replace with below
session.cache_limiter = public, max-age = 525600
session.cache_expire = 525600

Why it’s important to add cache control header?

to save bandwidth, cpu resources, Faster loading from user local storage.
to indicate proxy servers like cdn.
to communicate with proxy servers load balancing.
tools to check server /website performance.
gtmetrix, pagespeed insights, lighthouse, webpagespeedtest.org.
request headers
if modified since, if none match
also read if modified since, browser caching,  keep alive

Related topics:

  1. enable browser caching in wordpress apache nginx caching headers explained
  2. what is If-Modified-Since HTTP header how to add to WordPress website
  3. enable caching in apache server (mod cache disk cache) vs fastcgi cache
  4. W3TC w3 total cache plugin setup guide review comparison with wp rocket and wp super cache
  5. how to enable KeepAlive connections in apache nginx wordpress

tutorials

  • Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment
  • xampp tutorials 2021 installation errors fix wordpress phpmyadmin mysql apache
  • Devops Syllabus topics PDF
  • CCNA Syllabus pdf (CCNA / CCNP vs devops vs mcsa /MCSE)
  • how to create a website free of cost on google
  • what is vpn vs proxy vs tor, http vs https, http2, tcp vs udp, kali linux sql source code injection
  • nginx server tutorials (installation, configuration, performance tuning, security)
  • Vivek Bindra Videos Transcription (business strategy)
  • AUdio Editing Background Noise removal (Audacity, Adobe Premiere Addition, Camtasia Filmora Windows Obs)
  • MySQL Tutorial (create,connect database, update tables, export etc) Documentation & TIPS
  • [INTRO] Ethical hacking / cyber Security / Penetration testing Tutorial -{updates frequently}
  • ubuntu tutorials installation download issues etc
  • Php tutorials
  • HTML & CSS Tutorials
  • Core Java Tutorial Free online
  • Linux sysadmin tutorials linux system administrator
  • apache server tutorial (install,config, performance tuning, security, error handling)
    • what is If-Modified-Since HTTP header how to add to Wordpress website
    • htaccess tutorial tips for wordpress #redirect #leverage browser cache #Gzip #KeepAlive
    • apache modules list (explained, enable disable)
    • connect to server by SSH client Putty SFTP client winscp LAMP, LEMP nginx apache etc linux
    • Lamp stack install on Ubuntu 20.4 LTS apache, mysql, php 7.4(Debian 9 & Ubuntu 18.04 lts)
    • apache performance tuning mpm-worker vs prefork vs event modules
    • enable caching in apache server (mod cache disk cache) vs fastcgi cache
    • how to enable KeepAlive connections in apache nginx wordpress
    • Cache control Header & expires headers How to set Properly
    • apache2 conf sample explained apache configuration file modules etc

 

PUBG Mobile Tips & Tricks

free fire how to play (a-z guide) guns, tips &#038; tricks etc

Windows 10 tips & tricks

Pagespeed optimization

Pc building tips & tricks

nginx server tutorials

apache server tutorials

linux sysadmin tutorials

mysql Commands list pdf

Android studio tutorials

Gaming/ streaming tips

Airtel dth channel list

 

wordpress

 

Top 5  WP Google Analytics Plugins

WP Backup Plugins

Wp Comment Plugins

Top wordpress Security Plugins

WP Seo Plugins

WP Caching Plugins

Best Adsense Plugins for WordPress

Wp social Sharing Plugins

autoshare social media plugins

WP speed Optimization Plugins

Speedup WordPress google Score

More Wp tuts

Server Admin Cloud

 

Installing Nginx LEMP On ubuntu

Installing apache Lamp ubuntu

nginx fastcgi cache enable

php – fpm install  & Configuration

Opcache install & Configure

php -fpm pool manager explained

Mysql Install & Configuration

Redis Object cache install & configure

 

Nginx as Reverse Proxy and Load balancer

Load Balance / auto scaling in google cloud

Linux Commands PDF

Mysql Commands Pdf

Letsencrypt tutorial

mysqldump export & import 

Pagespeed Module install & configure

nginx.conf best file

mysql.conf best file

upgrade ubuntu

© 2021 - All Rights Reserved Disclaimer & Privacy Policy