Enabling Gzip in IIS on Windows 8

I recently needed to setup Gzip on my somewhat new Windows 8 VM and had to lookup how to do that. It had static compression enabled by default but something had to be separately installed before dynamic compression would be available, and that is what I needed before any of my server-side generated assets could be Gzipped. This would, for example, apply to all of my rendered ASP.NET MVC views. So I can find it more easily next time (there is no way I will remember how to do this in six months), I decided to just post this here on the blog. Maybe it will do some good for someone else.

How to tell if a response is Gzipped

First of all, to tell if you have a page from IIS being Gzipped, you can look at the HTTP response. Here is a sample request...


GET http://localhost:45002/blog/2013/6/7/enabling-gzip-in-iis-on-windows-8 HTTP/1.1
Host: localhost:45002
Connection: keep-alive
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Pragma: no-cache
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,fr-CA;q=0.6,fr;q=0.4

...and the response.


HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 07 Jun 2013 13:46:27 GMT
Content-Length: 9492


<!DOCTYPE html>

The request says that the browser accepts Gzip but the response is not compressed. Here is what a Gzipped response would look like:


HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 07 Jun 2013 13:50:04 GMT
Content-Length: 3604

...crazy encoded character stuff here...

The key differences will be the new Content-Encoding: gzip header and the content of the response will now be unreadable since it is encoded. So that is how you know if a response is Gzipped.

Installing dynamic compression

If you do find that you do not have Gzip installed, here is how you would solve that problem. First, go in IIS to the website you are hoping to tweak and hit the Compression page. If Gzip is not installed, you will see something like the following.

IIS without Gzip installed

Oh snap, “The dynamic content compression module is not installed.” We should fix this. So we go to the “Turn Windows features on or off” and select “Dynamic Content Compression” and click the OK button. It installs. Yay.

Install the dynamic content compression iis stuff

Now if we go back to IIS, we should see that the compression page has changed. It should look like the following:

IIS with Gzip installed

At this point we need to make sure the dynamic compression checkbox is checked and we’re good to go. Compression is enabled and our dynamic content will be Gzipped.

comments powered by Disqus