我想向浏览器提供一些静态内容,发现Brotli将最终下载包的大小比gzip减少了43%。
我首先尝试只设置Brotli和所有现代浏览器下载压缩文件。但当尝试使用IE11 (不支持brotli)时,请下载原始内容而不进行任何压缩,这会影响性能。
为了处理这个问题,我把Gzip和Brotli都放在了IIS上。但是现在所有的浏览器都只下载Gzip格式的内容,很可能是因为gzip优先的请求头顺序。
我想让它成为有条件的,以便在默认情况下浏览器下载Brotli格式的内容,如果浏览器不支持它,那么自动切换到gzip格式。
你知道怎么做吗?
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<scheme name="br" dll="%Windir%\system32\inetsrv\brotli.dll" dynamicCompressionLevel="5" staticCompressionLevel="11" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" 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="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="image/svg+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>发布于 2020-07-27 17:00:53
您可以启用多种压缩方案,包括Brotli和Gzip压缩,并设置压缩方案的优先顺序。
IIS提供了一个默认的压缩方案提供程序gzip,默认情况下它在applicationHost.config中注册为gzip方案。但是,如果您还想使用Brotli压缩,则需要在applicationHost.config中添加iisbrotli.dll作为Brotli压缩方案提供程序。Add Brotli compression scheme
关于如何设置压缩方案优先级,分为两个版本: IIS 10.0版本1803及以上和IIS 10.0版本1803之前。
关于IIS 10.0版本1803或更高版本,每个压缩方案的优先级由其在元素集合中的顺序确定。
大约在IIS 10.0版本1803之前,它根据Accept-Encoding请求标头值中出现的方案顺序确定压缩方案的优先顺序,但对于浏览器在请求中设置Accept-Encoding: gzip、deflate、br标头的典型情况,IIS始终将gzip优先于br。一种可能的解决方法是安装URL重写模块并配置重写规则以修改Accept-Encoding标头值。Enabling Multiple Compression Schemes
https://stackoverflow.com/questions/63088504
复制相似问题