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:

Cache optimized Yslow Sitefinity result
Fig: Optimized website loading

And while you can control the caching of the page content itself from within Sitefinity (page>properties) there is no built in method to control static content like javascript, css or images.

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.

Network loading Sitefinity result
Fig: Chrome Network loading panel

Our content page, was not cached so it is fetched from the server each time. All of our static content types get returned with a 304 Not modified code so the browser won't download them again. And even the final JavaScript file, which gets loaded asynchronously gets cached in the browser.

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.