- [Instructor] Every file the browser receives
in response to a request will be stored
by the browser in its cache for later retrieval.
This ensures you don't have to re-download the style sheet
and JavaScript and images and everything else
every time you navigate to a page you've already visited.
You can control the caching of all of these assets
on your site to either prolong or shorten the time
an asset is cached, depending on your needs.
The recommendation is to try to cache assets
in the user's browser for as long as possible
unless you have a good reason not to.
In most server configurations,
you can specify the caching strategy
for individual file types.
In the server config examples provided
by the HTML5 Boilerplate Team,
you can get Boilerplate code for all of this
as in this example for Nginx.
Here, you can see we have a list
of all the different file types.
We have default caching length,
we have no content caching length,
we have CSS caching length of one year.
There are all these different types of content
and you can sift through and find the types of content
you want to cache and set the length
of each of these caches.
What you'll notice when you go through this is
for the most part, you want to have very long caches,
like a year or at least a month,
but for certain types of assets,
maybe assets that will change a lot over time,
you may want to reduce that length down
or you may even want to set it to zero
because this needs to be updated all the time.
All this said, if you're using a CDN,
chances are there's already a caching strategy in place
set by the CDN based on what makes
the most sense for the CDN.
And what makes the most sense for the CDN
will almost always make the most sense for you as well
because they care deeply about performance,
since performance is how they make their money.
So, as with compression, investigate
the existing caching strategies
for your host and your CDN
before embarking on advanced customization
and aim to build on the defaults they provide
rather than building something from scratch.