In a perfect world you aim for everything to be cached, except the actual page content to minimize the download time and speed up a visitors user experience.
Some caching might take place on the server, or by the browser but ideally you want to end up with a picture that looks somewhat like this:
In order to achieve this optimum setup, we need to turn to our web.config and define some logic.
First up is setting up a caching profile.In it we define various common extensions and tell IIS how to handle these files, in this cache we simply tell IIS to cache them on the client until they've changed.
The second step is to define which content gets compressed.We do this by telling IIS how to handle individual mime-types by simply iterating over the individual mime-types.
And finally, iterate static content mime-types to ensure they're properly served.First setup client-caching logic to use 31 days. Then for individual mime-types we remove the mapping and re-assign it. At the same time by adding the charset=UTF-8 we avoid any unicode/ascii character encoding conflicts.
Encapsulate these snippets in a
<system.webserver> tag at the bottom of your web.config, recycle and navigate to your project.
Now if you open the network tab on Chrome or Firefox and you will see similar results as below.
Tomorrow we'll take a look at how to configure these settings with web.config transforms to easily enable/disable caching and compression during the development stage.