Hey, everyone.
And welcome back.
Now, in the earlier lecture, we basically used our browser to look into how the cache control header
really works.
Now, in today's lecture we will be configuring our own Nginx Docker instance to include various kind
of cache control headers and we'll start with no store for now.
So let's go ahead.
I have my docker nginx container up and running.
Now before we start, what we'll do is we'll download these two images.
So let's do one thing.
So I have one image called as MC dot jpeg.
I'll copy the URL and I'll do a wget perfect.
And similarly I'll copy the node store dot PNG.
Perfect.
So I have done wget for both of them.
So you'll see both of these files are part of my docker.
Now just to avoid confusion, what I'll do, I'll rename the file called as Docker seed dot jpg and
I'll rename node store to Docker.
No store dot jpg dot PNG.
Perfect.
Now we have both the files up and running.
Now just to verify if everything is working, I'll do a curl hyphen i on http example.com
docker dot jpg.
You got a proper response and you will see there is no cache control header over here.
Similarly, I'll do a docker node store dot PNG and again you'll see there is no cache control header
over here.
So whenever you open this file in the browser, the browser will store the file in the cache depending
upon its own configuration.
So what we will be doing is for this specific file or for this extension, PNG extension, we will be
adding a new header called as cache control header, which signifies a no store directive.
So let's look into how we can do that.
So I'll go to our Nginx configuration.
And if you look into labs dot conf, we don't really have an explicit headers which are mentioned,
so we'll go ahead and create our own header.
So I'll say location for all the locations which ends with PNG or for all the extensions which end with
PNG.
I'll say root is for websites.
So this specific aspect I copied from here and there is one important configuration which is add header.
So add header will specify adding of new header in the response.
Now I'll say cache control.
And let me.
This actually is a problem with Nano somehow in Docker when you use the CMD.
So cache control will be no stored.
Okay.
And I'll close the file.
Let me do a nginx hyphen t.
Everything seems to be successful and I'll do a service.
Enginex restart.
Perfect.
So things seems to be working correctly now.
Let's do one thing.
Let's do a docker node store.
And now what you see is you see there is a new header called as cache control and the value is no stored.
Now we did one mistake.
There seems to be two colon over here.
This is not expected.
So.
So this is something which we added by mistake.
I'll just restart Nginx.
And let's try this out.
And perfect.
So now we have a perfect cache control header for Docker node store dot PNG.
So as expected, browser should follow this header and it should not store the docker node dot PNG.
However, when you talk about the docker dot jpg it as it does not have a cache control header browser
will go ahead and store this file in its cache.
So let's try this out.
I'll copy this URL and let's close the earlier terminal and I'll paste the URL Docker seed dot jpg.
Perfect.
So now we have the image.
Correspondingly, we'll copy the second URL, which is Docker node store and I'll paste it again in
my chrome.
Perfect.
So now we have both the images which you will see.
However, if you do a about cache, since these are the key, I'll just copy the URL so you have the
URL over your docker.
JPG.
You see the Chrome has cached this entry.
However, now if I do you see I do not really get any result over here.
And this is what the no store header basically is all about.
So last thing just to reconfirm, the ad header is basically used to add a header in the response.
Now it will not add header for all the response.
It will only add header for the response with the extension dot PNG.
So you have a location which is specific for extension dot PNG files and specific for any file which
ends with PNG.
The ad header directive will be included, so go ahead and try this out.
This is quite interesting and fun to do.
I hope this has been informative for you and I look forward to see you in the next lecture with the
next cache control directives.