Static compression in IIS does not work for htm, j

2019-02-22 14:06发布

I'm trying to configure IIS 7.5 to compress static htm and js files. Does anyone know why it does not work for me? Here is my web.config for the web site:

    <httpCompression>          
        <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/x-javascript" 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="*/*" enabled="false" />
        </staticTypes>
    </httpCompression>
    <urlCompression doStaticCompression="true" doDynamicCompression="false" />

Compression starts working when I set doDynamicCompression to true. But I can't use this option because it is disabled at my hosting.

Thank you.

3条回答
【Aperson】
2楼-- · 2019-02-22 14:38

What makes you think the compression is not working? Check the Event View logs. Static Compression module will sometimes throw an error saying the directory being used is invalid (mostly because it needs write permissions).

Double check with Fiddler or another HTTP debugging tool to be sure that the client is sending "Accept-Encoding" of GZIP/Deflate.

查看更多
爷的心禁止访问
3楼-- · 2019-02-22 14:53
萌系小妹纸
4楼-- · 2019-02-22 14:54

I removed the mimeType="application/x-javascript" from the dynamicTypes but left it in staticTypes. That allowed me to turn off dynamicCompression but still have javascript compressed.

I've read some posts that suggest that when you have the same mimeType in both dynamic and static, the value in dynamic wins. When dynamicCompression is off, but there is a match for it in the dynamicTypes, javascript is treated as dynamic and therefore off.

That doesn't explain why CSS works because mimeType="text/" is in both places. IIS must do a better job of determining dynamic vs. static content when it comes to CSS, or any text/.

查看更多
登录 后发表回答