如果启用了静态压缩,则不会压缩IIS中的gzip js [英] gzip js in IIS doesn't get compressed if static compression enabled

查看:211
本文介绍了如果启用了静态压缩,则不会压缩IIS中的gzip js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Squishit来缩小和捆绑JS并压缩IIS 7.5中我启用的捆绑文件选项(启用静态内容压缩)

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

问题是Js不会被压缩,而我只是缩小了js,但是如果启用动态内容压缩,那么Js会被压缩.

Issue is Js doesn't get compressed and I just get minified js but if I enable dynamic content compression then Js gets compressed.

现在,动态压缩的问题在于它不缓存文件,并且在每次请求时都必须进行压缩,这需要占用CPU的时间.

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.

有人可以帮我解决为什么js在静态内容压缩模式下不被压缩

Can someone help me out why js doesn't get compressed in static content compression mode

这是在客户端发送js的理想方法

and is this the ideal way to send js on client side

JS -> Minify JS (Squishit) -> Compress (Static /Dynamic)

推荐答案

静态文件的压缩是动态处理的,而IIS则认为该文件不常见.一旦文件被认为是频繁,它将被压缩和缓存.缓存的版本将继续提供,直到不再使用.您可以在IIS中使用2种配置设置来配置常用文件:

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:同一文件被视为频繁且已缓存之前,应请求几次?默认为2.
  • frequentHitTimePeriod:应间隔{frequentHitThreshold}次请求相同文件以便被缓存的时间间隔.默认为10秒.
  • 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.

请注意,无论您设置了frequencyHitTimePeriod如何,如果在1分钟后未请求,则频繁文件将总是不频繁.我不知道配置中是否有此设置.

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.

例如,将frequentHitThreshold设置为1,将意味着IIS始终认为该文件是频繁的,即使是从第一个请求开始也是如此.反过来,这将绕过动态压缩,并且只能通过静态压缩进行处理.

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.

或者您可以通过将staticCompressionIgnoreHitFrequency设置为true来完全绕过命中频率:

Or you could bypass the hit frequency altogether by setting staticCompressionIgnoreHitFrequency to true:

appcmd set config -section:system.webServer/httpCompression /staticCompressionIgnoreHitFrequency:"True"

请注意,动态(默认0)和静态(默认7)压缩的压缩级别不同,因此将返回2个不同的文件大小.

Note that the compression levels for dynamic (default 0) and static (default 7) compression are different so will return 2 different file sizes.

这也是为什么我首先遇到这个问题的原因:即使对动态压缩和静态压缩使用相同的级别,同一文件的ETag也有所不同.

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.

希望这会有所帮助.

这篇关于如果启用了静态压缩,则不会压缩IIS中的gzip js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆