6

I am trying to support GZip compression for my static files under IIS (which should be enabled by default but not) but not working so far. Here is the the section under <system.webServer> node inside the web.config file of the web app;

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/json" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/atom+xml" enabled="true" />
    <add mimeType="application/xaml+xml" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </staticTypes>
</httpCompression>

<urlCompression doStaticCompression="true" />

I tried it with Google Chrome. Here are the Request Headers;

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8

Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3

Accept-Encoding:gzip,deflate,sdch

Accept-Language:en-US,en;q=0.8

Cache-Control:no-cache

Connection:keep-alive

Host:my-website-url

Pragma:no-cache

User-Agent:Mozilla/5.0 (Windows NT 6.0) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30

These are the Response Headers;

Accept-Ranges:bytes

Content-Length:232651

Content-Type:application/x-javascript

Date:Thu, 04 Aug 2011 08:58:19 GMT

ETag:"a69135734a50cc1:0"

Last-Modified:Mon, 01 Aug 2011 12:56:37 GMT

Server:Microsoft-IIS/7.5

X-Powered-By:ASP.NET

I check the applicationHost.config file and found some nodes like below;

----

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />

----

<section name="urlCompression" overrideModeDefault="Allow" />

----

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>

----

<urlCompression />

What am I missing here?

3
  • Are you requesting compressible content? .css or .js VS .aspx
    – af-at-work
    Aug 5, 2011 at 18:57
  • did you look at the response headers? Content-Type:application/x-javascript
    – tugberk
    Aug 5, 2011 at 19:04
  • Please see my answer to this question. It may help... serverfault.com/questions/505788/…
    – ianbeks
    Jul 23, 2014 at 9:25

3 Answers 3

3

It appears you may not have permissions set correctly on the temp compression folder. You ned to ensure the user your IIS install (or application) is running as has write permission to the compression folder.

More here

6
  • thanks for the input. that could be the real issue as you described. Do I need to set permission for all of the users of my web apps on the iis? because I am nearly 20 apps running and every app has their own user account on the server.
    – tugberk
    Aug 5, 2011 at 19:03
  • Why not try it with one app user to see how it works. After that, solving the permissions problem is often a creative task. Keep in mind that if the users are Windows authenticated, they may be the ones that need permissions.
    – uSlackr
    Aug 5, 2011 at 19:26
  • "IIS Temporary Compressed Files" folder has IIS_IUSRS users full control permission. What is missing I am really wondering here.
    – tugberk
    Aug 5, 2011 at 19:32
  • I granted one site's user to full control on "IIS Temporary Compressed Files" folder, still no luck.
    – tugberk
    Aug 5, 2011 at 19:32
  • Is my config code ok? did u have a chance to look at it.
    – tugberk
    Aug 5, 2011 at 19:35
1

After a lot of searching, I finally found what got compression working on my IIS 7.5. To start with, IIS will not compress a file unless it loaded often enough. That brings up the question "what does IIS consider often enough?" Well, the defaults are 2 times every 10 seconds. Yikes!

This setting can be changed in web.config, but the section needs to be unlocked first in applicationHost.config. Here are the commands:

First unlock the section:

C:\Windows\System32\inetsrv\appcmd.exe unlock config /section:system.webServer/serverRuntime

Unlocked section "system.webServer/serverRuntime" at configuration path "MACHINE/WEBROOT/APPHOST".

Now that is done, edit the web.config file and add the serverRuntime element:

<?xml version="1.0" encoding="UTF-8"?> <configuration>
    <system.webServer>
        <serverRuntime frequentHitThreshold="1" frequentHitTimePeriod="10:00:00" />
        ...

In this case, I set it to hit the file once in a 10 hour period. You can adjust the values as necessary. Here is the document that explains the serverRuntime element:

http://www.iis.net/configreference/system.webserver/serverruntime

I hope this helps get your compression working as well.

Note: you can also set the serverRuntime element up in the applicationHost.config file, but I chose to change it in the web.config because we have a number of servers and farms with various sites, and it is easier for me to control it from this level of granularity.

1
-1

This is working for me:

 <urlCompression doStaticCompression="true" doDynamicCompression="true" dynamicCompressionBeforeCache="true" />
<httpCompression noCompressionForRange="false" noCompressionForHttp10="false" noCompressionForProxies="false">
  <dynamicTypes>
    <add mimeType="text/css" enabled="true" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/css" enabled="true" />
  </staticTypes>
 <staticTypes>
    <add mimeType="text/javascript" enabled="true" />
  </staticTypes>
</httpCompression>

There is also text/javascript mime-type, and you only have application one. It was an issue until I included text/...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .