Turning off caching using .htaccess
Caching improves website performance by storing files in a visitor’s browser. However, during development or troubleshooting, you may want to disable caching so changes are reflected immediately. On ruachost.com, you can control caching behavior using the .htaccess file.
Why Turn Off Caching?
Section titled “Why Turn Off Caching?”- Ensure visitors see the latest version of your site.
- Prevent browsers from serving outdated files.
- Useful when testing new designs, scripts, or content.
Steps to Disable Caching
Section titled “Steps to Disable Caching”Step 1: Edit the .htaccess File
Section titled “Step 1: Edit the .htaccess File”- Log in to your hosting account via FTP, SFTP, or File Manager.
- Navigate to your site’s root directory (
public_html). - Open or create the
.htaccessfile.
Step 2: Add Cache‑Control Directives
Section titled “Step 2: Add Cache‑Control Directives”Insert the following code at the bottom of the .htaccess file:
# 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>Step 3: Save and Test
Section titled “Step 3: Save and Test”- Save the
.htaccessfile. - Clear your browser cache.
- Reload your site to confirm changes are applied.