How to verify if website caching is working?

Checking if the content of the website is delivered through caching server

Brief CDN and Cache Server Background

A cache server is a dedicated server or service acting as a server that saves Web pages or other Internet content locally. By placing previously requested information in temporary storage, or cache, a cache server both speeds up access to data and reduces demand on origin server bandwidth. There are quite a few options out there for enabling caching on your server. If you are going for a third party service, caching comes with CDN services. CDN stands for content delivery network — a large distributed network of servers (usually in a variety of locations around the world) that’s used to serve a website’s files (usually static files such as images, CSS and JavaScript files) to its visitors. Some top ones are Cloudflare, Amazon’s cloud front and Max CDN.

CDNs help solve the problem of slow server response times by storing copies of the files that go together to form your webpages (such as images, CSS and JavaScript files) in multiple locations around the world. When someone visits your website, these files will be delivered to them from the closest CDN server. This combination of delivering static files with reduced server response times is how content delivery networks can help drastically improve website loading times.

Here i’ll show you three ways to verify if your website or a resource is being served through cache or not.

  1. Via Developer Tools
  2. Via Command-line or Terminal
  3. Via Third Party Website

Option 1 (Browser developer tools  e.g Chrome’s “Network” tab or Firebug)

In order to view details of a resource on developer tools, you need to go to the “Network” tab. Then click a resource in the left panel. This’ll open up details related to that particular item. Head over to headers tab. In this example, we’re looking at http://talkwithstranger.com/free-chat-rooms where content is served via Cloudflare. You need to keep an eye on the following status message.

CF-Cache-Status: HIT
Resource was served through Cloudflare
Served through CloudFlare

Served through CloudFlare

Option 2 (Command line/ Terminal)

Just open your command line or terminal and paste the following command.

curl -svo /dev/null http://talkwithstranger.com
Cache check via terminal

Cache check via terminal

Option 3 (Third Party Website)

This one is very easy to use as you don’t really need any additional tool except your browser. You can verify if your site or a specific resource is being cached is to use webpagetest.org. If you put the url in and run a test, you can then go to the details page on webpagetest.org after the test has run. The response headers will show the following if the CDN is caching your site or a specific resource:

Webpagetest.org request response result

Webpagetest.org request response result

Various types of Caching responses

  1. HIT: resource in cache, served from CDN cache
  2. MISS: resource not in cache, served from origin server
  3. EXPIRED: resource was in cache but has since expired, served from origin server
  4. STALE: resource is in cache but is expired, served from CDN cache because another visitor’s request has caused the CDN to fetch the resource from the origin server. This is a very uncommon occurrence and will only impact visitors that want the page right when it expires.
  5. IGNORED: resource is cacheable but not in cache because it hasn’t met the threshold (number of requests, usually 3), served from origin server. Will become a HIT once it passes the threshold.
  6. REVALIDATED: REVALIDATED means we had a stale representation of the object in our cache, but we revalidated it by checking using an If-Modified-Since header.
  7. UPDATING: A status of UPDATING indicates that the cache is currently populating for that resource and the response was served stale from the existing cached item. This status is typically only seen when large and/or very popular resources are being added to the cache.
2017-03-29T10:17:46+00:00

Leave A Comment