Overview

You can set this header by adding a rule to your web server’s configuration file. There are several options that can be set but we will only focus on the three(3) popular ones which restrict caching. They are:

  1. Cache-Control: no-cache
  2. Cache-Control: no-store
  3. Cache-Control: private

Note: Different web servers have different configuration files. Choose the one below that applies to your website.

Configuring on Apache web server:

Using .htaccess configuration file.

If you’re on a shared hosting plan, you’ll only have access to create rules in the .htaccess configuration file. Follow these steps:

  1. Go to your website’s root folder, open the .htaccess file. Note: You should be able to do this using either an FTP application such as Filezilla or your hosting provider’s online File manager.
  2. Copy one (1) of the following lines into the .htaccess (after any existing rules) and save it. The header should now be set.
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: private

 

Using httpd.conf configuration file

If you’re on a dedicated hosting plan that gives you access to the web server’s root configuration file httpd.conf, then:

  1. Go to your website’s root folder, open the httpd.conf. Note: You should be able to do this using either an FTP application such as Filezilla or your hosting provider’s online File manager.
  2. Copy one (1) of the following lines into the httpd.conf file (after any existing rules) and save it. The header should now be set.
header always set Cache-Control "no-cache
header always set Cache-Control "no-store
header always set Cache-Control "private"

 

Microsoft IIS web server

 

<httpProtocol>
    <customHeaders> 
    		<add name="Cache-Control:" value="no-cache" />
    </customHeaders>
</httpProtocol>

 

<httpProtocol>
    <customHeaders> 
    		<add name="Cache-Control:" value="no-store" />
    </customHeaders>
</httpProtocol>

 

<httpProtocol>
    <customHeaders> 
    		<add name="Cache-Control:" value="private" />
    </customHeaders>
</httpProtocol>

 

NGINX web server

Copy one(1) of the following lines into server block configuration.

add_header Cache-Control "no-cache" always;
add_header Cache-Control "no-store" always;
add_header Cache-Control "no-private" always;

NOTE: Some CMSs such as WordPress offer plugins you can use to set headers using a point and click type interface, in case you feel uncomfortable modifying the configuration file directly.

 

How to verify the Cache-Control header is set

Use your browser’s built-in function to view HTTP Headers as below:

Using Google Chrome and Firefox browser:

  • Open the web page
  • Right-click anywhere on the page and select “Inspect element”
  • Go tot he “Network Tab”
  • Refresh the page and select the page’s URL from the list of loaded resources
  • Look under the panel for “Response Headers” to see if the cache-control is set as you configured.

Why implement the Cache-Control Header

This header should when you want to control what is cached by a user's browser and computer when they use a website/ web application.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.