From 8fe4bc5472564372ef917796e0aaa4148d43a095 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 13 Nov 2019 21:47:27 +0400 Subject: [PATCH] Add TOCs to http-caching --- data/guides/http-caching.md | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/data/guides/http-caching.md b/data/guides/http-caching.md index 1133dc730..e90d1ef69 100644 --- a/data/guides/http-caching.md +++ b/data/guides/http-caching.md @@ -1,5 +1,3 @@ -In one of the previous posts, I discussed about [HTTP and where it stands at this point](/guides/journey-to-http2). This is one is going to be specifically about the caching. - As users, we easily get frustrated by the buffering videos, the images that take seconds to load, pages that got stuck because the content is being loaded. Loading the resources from some cache is much faster than fetching the same from the originating server. It reduces latency, speeds up the loading of resources, decreases the load on server, cuts down the bandwidth costs etc. ### Introduction @@ -23,7 +21,11 @@ Before we get into further details, let me give you an overview of the terms tha ### Caching Locations -Web cache can be shared or private depending upon the location where it exists. Below is the list of caching locations +Web cache can be shared or private depending upon the location where it exists. Here is the list of different caching locations + +- [Browser Cache](#browser-cache) +- [Proxy Cache](#proxy-cache) +- [Reverse Proxy Cache](#reverse-proxy-cache) #### Browser Cache @@ -51,6 +53,22 @@ Although you can control the reverse proxy caches (since it is implemented by yo So, how do we control the web cache? Whenever the server emits some response, it is accompanied with some HTTP headers to guide the caches whether and how to cache this response. Content provider is the one that has to make sure to return proper HTTP headers to force the caches on how to cache the content. +- [Expires](#expires) +- [Pragma](#pragma) +- [Cache-Control](#cache-control) + - [private](#private) + - [public](#public) + - [no-store](#no-store) + - [no-cache](#no-cache) + - [max-age: seconds](#max-age) + - [s-maxage: seconds](#s-maxage) + - [must-revalidate](#must-revalidate) + - [proxy-revalidate](#proxy-revalidate) + - [Mixing Values](#mixing-values) +- [Validators](#validators) + - [ETag](#etag) + - [Last-Modified](#last-modified) + #### Expires Before HTTP/1.1 and introduction of `Cache-Control`, there was `Expires` header which is simply a timestamp telling the caches how long should some content be considered fresh. Possible value to this header is absolute expiry date; where date has to be in GMT. Below is the sample header @@ -104,7 +122,7 @@ Cache-Control: no-store Cache-Control: max-age=3600, no-cache, public ``` -#### max-age: seconds +##### max-age: seconds **`max-age`** specifies the number of seconds for which the content will be cached. For example, if the `cache-control` looks like below: ```html