Search Our Database

How to prevent HTTP file caching with .htaccess

Last updated on |
under |

Some websites use highly volatile, oft-changing CSS and JavaScript files. In the case of these files, it’s important that the developer prevents browsers from caching them so that you and your visitors will see the latest CSS and JavaScript files instead of the old and cached version.

There are many ways to prevent your page from being cached and in this tutorial guide, we will do just that using .htaccess.

Step 1 – Login into your web server.

Step 2 – Proceed to the following directory /var/www/html and list all the available files.

cd /var/www/html
ls -asl

Step 3 – If there is already a .htaccess file, you can open and edit it right away. If there is none, you will need to create a new .htaccess file.

touch /var/www/html/.htaccess

Step 4 – Change the file’s permission so that it is writeable by Apache.

chown apache /var/www/html/.htaccess

Step 5 – Open to edit .htaccess file.

vi /var/www/html/.htaccess

Step 6 – Copy and paste the following codes into .htaccess.

<FilesMatch "\.(html|htm|js|css|php)>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"

Step 7 – Save and exit!

.htaccess will now not cache your website.

Dedicated Server from RM549/mth!

Check out IPServerOne’s Dedicated Server Packages.
Contact us @ +603-2026-1688 or email @