InMotion Hosting Support Center

There are times when you must disable caching of your website files. You would want to stop it by letting any browser accessing your site know that it should not cache the files. The best way to do this is to use directives written in the .htaccess file. As we are using the Apache server there are a couple ways of adding these commands in the .htaccess file. It may depend on the software you are using to display your website. If you are unsure, then you should speak with a developer to be sure.

Conditions for Disabling Caching

Some conditions for not wanting caching on a viewer's internet browser include:

  • Constantly updated data that you do not want to be cached (e.g. stock ticker)
  • Caching structures that you prefer to use on your server
  • Pages requiring login verification that include updates that change regularly

.htaccess Code for Disabling Caching

There are a few different versions of code that you can add to disable cache. We have provided two examples of code that you can use in the .htaccess file to disable caching. The older version identifies the file types that you do not want to be cached. The newer version which uses cache-control to use in .htaccess. Please feel free to look at the code and use it in your .htaccess file to disable caching if necessary.

Things to consider when adding the code to .htaccess

Remember that .htaccess files are read from top to bottom, so if you want these directives to occur before something else, then they should be placed higher within your .htaccess file. Bear in mind that there may be multiple .htaccess files and that .htaccess files placed above another in a directory will have precedence over the one placed in a sub-directory.


Examples of the code used to disable caching

Example #1:
<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>

Example# 2

# 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>

This completes the tutorial on disabling caching using the .htaccess files. For more information on the .htaccess file, please see Where is my .htaccess File?

Was this article helpful?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Forum Login

You are NOT logged in. You can still browse our Support Center.

To participate within our Community Support Forum:

n/a Points
2018-09-25 12:10 am

What is the difference in these two methods? Is one better than the other for certain cases?

Staff
11,000 Points
2018-09-25 8:43 am
The differences are explained in the text of the article. Both have the same effect. It depends on what you're trying to do. I'd advise trying both.

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

2 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!