I have the following web.config:
<urlCompression doStaticCompression="true" />
<httpCompression>
<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>
May plan does not allow Dynamic compression
The problem is, when I request css or js, IIS respond with GZIP and add vary:accept-encoding sometime and other time does not compress CSS nor JS, I can't find the pattern it is some kind of random.
I always try CTRL F5, even when you access www.mysite.com css and js are randomly compressed or not.
NB: hosted on NetworkSolution.
What's wrong with my config or IIS.
Thanks
The easiest, quickest thing is to take a look at the Developer Tools Network tab and see if the Content and Size values for each request are different. If the values differ, then compression is working.
On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Performance, and then select Static Content Compression and/or Dynamic Content Compression. Click Next.
Select the Internet Information Services (IIS) Manager under Roles > Web Server (IIS). In the IIS Manager, select the desired Site and open the Compression option (Features View). In the Compression window, mark the check box corresponding to the Enable dynamic content compression option.
IIS Dynamic Compression configuration: Dynamic compression is a feature that allows the IIS web-server to compress responses coming from such handlers as the ASP.net Managed Handler, ISAPI Extensions or CGI handlers that dynamically generate responses for requests they handle.
Static Compression: IIS 7 caches compressed static content in the path that is specified by the directory attribute, which increases compression performance by eliminating the need to recompress content that has already been compressed.
Static content does not change. However, dynamic content is typically content that is created by an application and therefore changes often, such as Active Server Pages (ASP) or ASP.NET content. Since dynamic content should change often, IIS 7 does not cache it.
If the behavior is not disabled, a hit rate of greater than or equal to two hits in 10 seconds will result in compression of the static content. A lesser hit rate would result in the content not being compressed. The default value is False. Optional element. Specifies the compression scheme (Gzip or Deflate) IIS uses to compress client requests.
I'm using Windows Server 2012 R2 Standard, and IIS 8.5.9600.16384. I installed both static and dynamic content compression, and as you can see both are checked: Also I went to configuration editor, and there I can see that JavaScript should be compressed:
After a lot of searching, I finally found what got compression working more consistently 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
<?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 properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With