You are here: / Articles / Guides / Technology / How to set HTTP Headers for Cache-Control

How to set HTTP Headers for Cache-Control

Cache-Control

Share!



Web developers are always finding new ways to speed up the experience for the website visitors. There is one not so new way to add to the performance that is not quite used to its extent and that’s the Cache-control.

The cache can be controlled from the server side, from the DNS, reverse proxies, and more. However, today we will be looking at how to do this using the HTTP headers for cache control using HTML.

Pragma, the HTTP/1.0 Implementation

The throwback to the days of HTTP/1.0 what was used was the Pragma directive. Though it is no longer recommended, I have included it here for nostalgic purposes.

<meta http-equiv="pragma" content="no-cache">

If that is no longer recommended and even fails on various HTML validators, what is the correct way to do this?

Cache-Control, the HTTP/1.1 Implementation

With HTML5 and HTTP/1.1, it is recommended that one used the cache-control implementations. With just a couple of changes, you are on your way to properly get web browsers to cache your web pages.

This is the HTTP/1.1 implementation with cache-control.

Read Also  Your Simplified Guide to CSS Stylesheet Media Types

<meta http-equiv="Cache-control" content="public">
<meta http-equiv="Cache-control" content="private">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="no-store">

What Else is There to Cache-Control?

As you can see from above, the Cache-control uses meta tags. But like most meta tags, they support more than a single value for any directive and the Cache-control is no exception.

In this case, the allowed values are:

Public: This states that the content may be cached in public shared caches.
Private: This one hints that the content may only be cached in private cache.
no-Cache: This value hints that the content may not be cached.
no-Store: Used to tell the caches that the content may be cached but not archived.

There you have it. You should now be equipped enough to effectively use the HTTP headers for Cache-control.