In case you’ve wondered,
I spent an hour or so trying to figure out performance bottlenecks in a ASP.NET MVC 4 application using Googles DevTools. I almost immediately saw that not a single request (of about 17 required to server a page) had a Cache-Control header set. Also, none of the responses had an Encoding header set to gzip. However, I was running this locally and I smelled a rat.
But still, I thought, well here’s some low hanging fruit. But no. I forced compression in my application by setting the web.config element
<urlCompression doStaticCompression="true" />
I also added
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
in an attempt to enable caching, but no again. No cache-control headers were set.
So, in order to rule out mistakes I reconfigured my application to use IIS Express (v 8) without changing my web.config. And guess what. Content caching was working immediately. But what about Gzip compression? Well, it turns out that the default IIS Express configuration is set to compress files with MIME-type
To fix that as a default server setting (rather than in your web.config), you can go to the IIS installation folder
cd %programfiles%\IIS Express and run the command
VoilÃ¡, compression enabled.
Lesson learned: don’t expect things to be configured correctly by default. Also, don’t use the built-in server, use IIS Express instead. It’s gonna save you some time since it is more likely you will find odd behavior before deploying on a real IIS web server.