How can I enable IIS7 to gzip static files like js and css and how can I test if IIS7 is really gziping them before sending to the client?
10 Answers
Configuration
You can enable GZIP compression entirely in your Web.config
file. This is particularly useful if you're on shared hosting and can't configure IIS directly, or you want your config to carry between all environments you target.
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>
Testing
To test whether compression is working or not, use the developer tools in Chrome or Firebug for Firefox and ensure the HTTP response header is set:
Content-Encoding: gzip
Note that this header won't be present if the response code is 304 (Not Modified). If that's the case, do a full refresh (hold shift or control while you press the refresh button) and check again.

- 12,154
- 8
- 64
- 80

- 300,895
- 165
- 679
- 742
You will need to enable the feature in the Windows Features control panel:

- 8,530
- 2
- 55
- 53
-
17In Windows Server 2008 R2, this is located under Server Manager > Roles > Web Server (IIS). Click "Add Role Services" in the "Roles" section. "Dynamic Content Compression" is listed under the "Performance" header. – Jonathan Little Dec 10 '15 at 15:18
Global Gzip in HttpModule
If you don't have access to the final IIS instance (shared hosting...) you can create a HttpModule that adds this code to every HttpApplication.Begin_Request event :
HttpContext context = HttpContext.Current;
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip");
HttpContext.Current.Response.Cache.VaryByHeaders["Accept-encoding"] = true;
Testing
Kudos, no solution is done without testing. I like to use the Firefox plugin "Liveheaders" it shows all the information about every http message between the browser and server, including compression, file size (which you could compare to the file size on the server).

- 12,154
- 8
- 64
- 80

- 5,044
- 2
- 33
- 43
-
3I'm using shared hosting and didn't need to write any code to enable GZIP output compression. It was possible via Web.config alone. See my answer: http://stackoverflow.com/questions/702124/enable-iis7-gzip/5444505#5444505 – Drew Noakes Mar 26 '11 at 18:55
-
2I placed the first three lines at the start of the one aspx page I wanted to compress, and it works! Thank you! This is so much less hassle than any other approach, and it works on IIS 6 for me. – DenNukem Apr 27 '11 at 20:10
-
1
I only needed to add the feature in windows features as Charlie mentioned.For people who cannot find it on window 10 or server 2012+ find it as below. I struggled a bit
Windows 10
windows server 2012 R2
window server 2016

- 10,464
- 6
- 51
- 80
If you are also trying to gzip dynamic pages (like aspx) and it isnt working, its probably because the option is not enabled (you need to install the Dynamic Content Compression module using Windows Features):
http://support.esri.com/en/knowledgebase/techarticles/detail/38616

- 3,116
- 3
- 30
- 51
If you use YSlow with Firebug and analyse your page performance, YSlow will certainly tell you what artifacts on your page are not gzip'd!

- 935
- 5
- 7
Another easy way to test without installing anything, neither is it dependent on IIS version. Paste your url to this link - SEO Checkup
To add to web.config: http://www.iis.net/configreference/system.webserver/httpcompression

- 6,006
- 6
- 48
- 68
Try Firefox with Firebug addons installed. I'm using it; great tool for web developer.
I have enable Gzip compression as well in my IIS7 using web.config.

- 98,673
- 67
- 256
- 322

- 17
- 1
-
Google also has a page test available: https://developers.google.com/speed/pagespeed/insights/ – Dr. Aaron Dishno Feb 25 '16 at 19:45
And if you decide to edit `%windir%\System32\inetsrv\config\applicationHost.config` on x64 bit Windows via a Notepad++ or any other 32bit editor, you may need to use another path, see: http://forums.iis.net/t/1151982.aspx