Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS 7.5 Static Content Compression (not consistent )

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

like image 758
Sameh Avatar asked Mar 19 '13 12:03

Sameh


People also ask

How do I know if IIS compression is working?

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.

How do I enable static compression in IIS?

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.

How do I enable dynamic content compression in IIS 7?

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.

What is IIS dynamic compression?

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.

What is static compression in IIS 7?

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.

What is static and dynamic content in IIS 7?

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.

What is the default hit rate for compression in IIS?

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.

Does Windows Server 2012 R2 standard support static and dynamic content compression?

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:


1 Answers

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.

like image 51
Brain2000 Avatar answered Oct 03 '22 15:10

Brain2000