I have used Squishit to minify and bundle JS and to compress Bundled file I enabled option (Enable Static content compression) in IIS 7.5
Issue is Js doesn't get compressed and I just get minified js but if I enable dynamic content compression then Js gets compressed.
Now problem with dynamic compression is that it does not cache the file and on each request it has to do the compression that take time of CPU.
Can someone help me out why js doesn't get compressed in static content compression mode
and is this the ideal way to send js on client side
JS -> Minify JS (Squishit) -> Compress (Static /Dynamic)
Check the httpCompression TypesCheck the httpCompression section in applicationHost. config file, you should find <add mimeType="application/x-javascript" enabled="true" /> . If this is correct, then it should be correctly configured in your IIS. This will start compressing your .
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.
When you want to check if content is compressed, you have to look at the content encoding of the response, and to check if the content length changes between compressed and uncompressed content. For example, this is a compressed object, notice the Content-Encoding header and the object size.
The compression of static files is handled dynamically while the file is considered infrequent by IIS. Once the file is considered frequent it will be compressed and cached. The cached version will continue to be served until it becomes infrequent again. There are 2 config settings you can use in IIS to configure frequent files:
system.webServer/serverRuntime:
frequentHitThreshold
: How many times should the same file be requested, before it's considered frequent and cached? Defaults to 2.frequentHitTimePeriod
: Time interval in which the same file should be requested {frequentHitThreshold} times, in order to be cached. Defaults to 10 seconds.Beware that regardless of the frequentHitTimePeriod you set, a frequent file will always become infrequent if it is not requested after 1 minute. I have no idea if there is a setting for this in the config.
Setting frequentHitThreshold
to 1, for example, will mean that the file is always considered frequent by IIS, even from the first request. This will in turn bypass the dynamic compression and be treated only by static compression.
Or you could bypass the hit frequency altogether by setting staticCompressionIgnoreHitFrequency
to true:
appcmd set config -section:system.webServer/httpCompression /staticCompressionIgnoreHitFrequency:"True"
Note that the compression levels for dynamic (default 0) and static (default 7) compression are different so will return 2 different file sizes.
Also and this is why I got into this issue in the first place: the ETag for the same file is different between dynamic and static compression even if you use the same levels for both.
Hope this helps.
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