1. Home
  2. General
  3. Turn Off Caching for Website
  1. Home
  2. PHP
  3. Turn Off Caching for Website

Turn Off Caching for Website

While disabling caching is sometimes necessary, it’s important to consider the performance impact, as caching often helps reduce server load and improve page load times.

To disable caching, add the following code to the bottom of your .htaccess file. To re-enable caching, simply remove the 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>
Updated on August 26, 2024

Was this article helpful?

Related Articles