Web Server: How to disable caching using .htaccess

More
28 Oct 2020 13:55 - 25 Aug 2026 04:42 #1 by Trony

After making a change to our Website (css, js, jpg, font, etc.), to make the changes immediate you need to disable the Cache.

With this code at the end of our .htaccess file, we forced a New Browser Session not to cache any files in its cache.

Please note: any previous session will remain in cache and you must clear the Browser Cache manually.

Code:
# DISABLE CACHING <IfModule mod_headers.c> Header set Cache-Control "no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires 0 </IfModule> <FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|mp3|mp4|png|pdf|swf|txt)$"> <IfModule mod_expires.c> ExpiresActive Off </IfModule> <IfModule mod_headers.c> FileETag None Header unset ETag Header unset Pragma Header unset Cache-Control Header unset Last-Modified Header set Pragma "no-cache" Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT" </IfModule> </FilesMatch>

Do You ❤️ It?!? Buy Me a Coffee! Thank You in advance... ✌️


Support me on Ko-fi

"Music and Electronic Devices Designer. Drum and Bass Addict. Creative Mind as Lifestyle. Cat in past Life. Football, Ice Hockey and Snowboard Lover. Marxist."


Sono Il Re sul Carro Danzante.
Attraversando La Città Getto Via I Coriandoli Della Vostra Tristezza Regalando Passione Ed Estasi Nei Vostri Occhi.

😼 This-Ads-Feeds-My-Cats