CDN No-Cache: Web Caching and HTTP Headers (101)
Browsers are always getting smarter and more efficient at delivering web content to their users every single day. The faster they can deliver the website content the better for them and the users hence the constant push for lighter, leaner websites, and web app interfaces. One of the technologies currently in use on all mainstream web browsers is web caching that you can also control with manual HTTP headers or through a CDN dashboard.
What Is Web Caching and How Does It Affect Your Website?
Web caching is an ingenious approach to enhancing user experiences on the web. It’s a browser-based technology that allows the user’s browser to store snapshots of certain web assets such as images, text, libraries, and scripts if they happen to visit your website frequently. This will allow them to load your website or web application faster and more smoothly as compared to if their browser were to grab it from your web server each time.
That said, web caches are not permanent as there is a time limit to when a user can have your web assets on their browser otherwise referred to as TTL (time to live). The caches will be deleted if the TTL expires before the user accesses your website again or automatically to cater to updates on your website.
Web caching is great if you are delivering non-sensitive content such as articles and images and have a loyal following on the web. Your web assets will load faster as if they were natively stored on your visitor’s internal memory thus allowing for a better user experience. This is especially important on mobile devices or for a user with bad internet speeds.
When You Don’t Need Web Caching
There are several instances where allowing browsers to keep caches of your web assets would not be ideal for a number of reasons. Here are some of them:
1. When You are Dealing with Sensitive information
There are web assets such as bank account details, login information, or user identity that cannot be cached by third-parties. For this, you will need to define cache directives in the HTTP headers that will disallow any kind of caching for security purposes.
2. Frequently updated Websites/ Realtime
In some instances, having an undefined caching policy might work against you as your visitors may not access real-time information. For instance, a web application loading dynamic text or images in real-time may not work as desired if Max-age directives are not set well in the HTTP headers.
How to Control Web Caching with Http Headers
There are two ways you can control how web caching works on your websites or web applications. You can choose the manual route where you set the directives in your HTTP headers or use a CDN to create more specific web caching rules using a graphical dashboard.
Here are the main web caching HTTP headers and what effect they have on the way your web assets are handled across the internet:
1. Cache-control: public
The presence of this blanket HTTP directive on your website’s server means that all the assets/resources on your website can be cached by any entity on the web including browsers, content delivery networks, and even other web servers such as the Way back machine or Google cache. Only use this directive if you are not dealing with sensitive information such as banking details or private user information. Most blogs and informational websites have this HTTP directive by default.
2. Cache-control: private
This HTTP directive disallows intermediary parties such as CDNs, search engine caching bots, and other web servers from keeping caches of your website’s data. However, it’s not practical to use this directive especially if you plan to use a CDN to deliver your content. The directive can be set to affect specific components that hold sensitive information only such as private or paywalled web assets.
3. Cache-control: max-age
The max-age HTTP directive is used to define how long a cache can be used before the client needs to send a request to your web-server. An alternative, but similar version called s-cache is used for CDN caches.
4. Cache-control no-cache
Using this directive on your HTTP header instructs browsers to first check if there is an update on your web server before serving a cached version of your web assets to the user.
5. Cache-control: no-store
This is a rarely used directive that prevents every entity including browsers from caching any content or asset on your website or web page. It’s mostly used where the website is dealing with secure or sensitive information such as bank account details, online transactions, private accounts, online dating accounts, etc.
Creating all these directives can become cumbersome and inefficient. By using a CDN to define your caching rules, you will have an easier interface and better control over what is being cached. The graphical user interface also helps you to see what directives are active and those that aren’t.
Power-up your Content Delivery
30 Day Free Trial Cancel Anytime