GZIP CSS and Javascript files in IIS - iis

I'm trying to deliver to the browser the Compressed & Gzipped version of my javascript files using coldfusion.
I've tried to add the following to the web.config but still not showing GZIP (using Fiddler)
<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"/>

I solved my problem by installing dynamic compression under IIS Roles Services and now it works like a charm.

With compression on in IIS there is no need to pre-compress the .js files. The server will manage compressing, checking for browser support and sending the compressed file when it is supported without you doing any work on your end.
You just need to put the js file on the server and you should be good to go. Just use the normal file name in the src for the script tag and the server will manage all of the rest of it. Since it is not a ColdFusion file the ColdFusion server doesn't ever touch it.

Isn't the browser just uncompressing it, like it should, and your seeing the the end result.
You could also use cfhttp to hit the same url, and see what it returns. With that, you can easily control and see what is compressed or uncompresed.

Only use the compression option in IIS, and directly link to the JS / CSS files, don't serve them via ColdFusion.
The content in your browser window has been minified, not compressed.
Browsers are aware of compressed content; the browser will tell the server what formats (if any) that they can handle. The compressed js file is automatically decompressed by the browser before you see it. This is why the content is see is plain text.
As for YSlow, make sure it is not complaining about uncompressed CSS files.

It looks like you've specified that the MIME type "application/x-javascript" should be compressed by IIS. However, you are returning the MIME type "application/javascript" from ColdFusion.

for css compression maybe you guys should try this attribute;
<add mimeType="text/css" enabled="true"/>
and its the entire code(leverage browser caching includes);
<system.webServer>
<httpCompression directory="C:\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="C:\Windows\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"/>
<add mimeType="text/css" enabled="true"/>
</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"/>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00"/>
</staticContent>
</system.webServer>

Related

Website on IIS server, gzip cache not working

I have a problem. I need to make PageSpeed scores as high as possible on my website. The thing is that the website is hosted on Microsoft IIS server and I can't turn on the gzip like I used to using .htaccess file on Apache server.
I found the solution that I need to edit the web.config file and this code:
<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>
But it doesn't help at all and PageSpeed tests still shows that my resources like .jpg, .js or .css files doesn't have an expiration date. Although they do have a gzip properties if I inspect them in browser network tool.
Any ideas what I could do to make the website pass the tests?
You might want to consider CDN. Specially for static files like CSS, images and .js files.
CDN lets you specify a TTL and that is probably what you are looking for.

Gzip not working - NO_MATCHING_SCHEME

Problems with activating Gzip on IIS 8 on a windows server 2012 (standard)
So i activated the compressions in the windows features
I checked both checkboxes in IIS - compression (dynamic and static)
But still no Gzip available. However, on my localhost machine (just a windows 10) this works.
What i do see, is that the gzip temp directory (C:\inetpub\temp\IIS Temporary Compressed Files) is getting filled up when i browse my site via the server localhost. BUT strangely enough i'm not seeing anything Gzip-ped in chrome.
The only headers (in chrome) are: HTTP/1.1 304 Not Modified Accept-Ranges: bytes ETag: "0a354779de8d11:0" Server: Microsoft-IIS/8.0 X-Powered-By: ASP.NET Date: Thu, 28 Jul 2016 13:41:04 GMT
(Even yslow is saying no gzip is activated)
When i remove the gzip temp folder, and browse to the site trough the 'official' website url, then nothing is even generated.
Does anyone has any idea what is going on here?
I added this in my web.config
<httpCompression>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4" />
</httpCompression>
See this other topic, where i activated more log information, Gzip not working, server 2012, IIS 8
All i get is:
<RenderingInfo Culture="nl-BE">
<Opcode>STATIC_COMPRESSION_NOT_SUCCESS</Opcode>
<Keywords>
<Keyword>Compression</Keyword>
</Keywords>
<freb:Description Data="Reason">NO_MATCHING_SCHEME</freb:Description>
</RenderingInfo>
Can you try adding this to your web.config file ?? I suggest so because it worked for me on IIS windows shared hosting. Its similar to your code with a few changes...
<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="application/javascript; charset=utf-8" 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/javascript" enabled="true"/>
<add mimeType="application/javascript; charset=utf-8" enabled="true"/>
<add mimeType="application/x-javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>
I'm not sure if you need to add
<add mimeType="image/jpeg" enabled="true" />
Isn't jpeg a compressed format ? You could add it none the less if you wish to.
[OPTIONAL]: I read this at MaxCdn.
Origin servers should include Vary: Accept-Encoding, and here’s how:
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Vary"></remove>
<add name="Vary" value="Accept-Encoding"></add>
</customHeaders>
</httpProtocol>
</system.webServer>
You can add this bit to your web.config file as well, deploy and check it in the request headers through your browser's developer tools itself.

Static content compression over Azure Web Role & Azure CDN not working

My website is hosted on an Azure WebRole and the content is fetched using Azure CDN.
The main HTTP request itself is compressed, but the static content (css & js are the main issue here) isn't.
The request is sent with 'Accept-Encoding: gzip,deflate,sdch' header, but the response is missing the 'Content-Encoding: gzip' and 'Vary: Accept-Encoding' headers.
It's important to note that this happens when fetching the content both from and the CDN and directly from the WebRole.
These are the relevant web.config sections:
<urlCompression doDynamicCompression="false" doStaticCompression="true" />
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" noCompressionForHttp10="false" noCompressionForProxies="false">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="image/svg+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
As you can see in the config, I've enabled compression for proxies and for HTTP 1.0, but it doesn't seem to be the problem.
Anyone has an idea what's wrong here?

Set up gzip in IIS 8 and Windows 8

I created the default MCV4 website and hosted in my local IIS8 in widows 8 system under default web site.
http://localhost/MyWesite
in IIS manager "Compression" enabled dynamic content compression and static content compression. also disabled file size limit for compression so all js file sized are considered for compression (still gzip compression did not happen)
Is this the only system level gzip configuration?
Then next I tried to do website level change. I also edited the applicationHost.config file in C:\Windows\System32\inetsrv\config below are the change I did
<section name="httpCompression" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
in the web.config file I added the following
<system.webServer>
<httpCompression>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4" />
</httpCompression>
</system.webServer>
After doing this I restarted iis just in case. On loading the webpage no js file or html document got gziped.
Probably you have already fixed this issue, it just happened to me and I found this while looking for the error. I had the exact same web.config configuration (worked perfectly on older webserver with IIS 7.5).
I found that you need to go to Server Manager and make sure that you have setup the Dynamic Content Compression feature, under Web Server => Web Server => Performance.

GZip compression in IIS7 not working, but content-encoding header is set to gzip

I have IIS 7.5 with static and dynamic compression enabled. It seems to work fine for dynamic files, but for static ones it behaves erratically, often sending a http header "Content-Encoding: gzip" when the content is not compressed. This causes browsers to attempt to uncompress, throwing an invalid magic number error. Here's my configuration:
<httpCompression dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="70" >
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="application/javascript" 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/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
I thought some http module was uncompressing the content somewhere down the pipe, but none of them seem suspicious. Any ideas?
Try to enable dynamic compression before cache which is disabled by default.
<urlCompression dynamicCompressionBeforeCache="true" doDynamicCompression="true" doStaticCompression="true" />
I have found out in my investigations that using HttpContext.RewritePath() on a static file causes this problem.
Took me a while to figure this out too. Setting the frequentHitThreshold attribute to 1 on the system.webServer/serverRuntime node in the applicationHost.config file should do the trick, as documented at http://www.iis.net/ConfigReference/system.webServer/serverRuntime.
You can do this by executing the following command as an administrator:
%windir%\system32\inetsrv\appcmd set config /section:serverRuntime /frequentHitThreshold:1 /commit:apphost
A word of warning - the "frequent hit" concept does not seem specific to compression. I have no idea whether there are other consequences as a result of setting this!

Resources