0
votes

I want to server some static contents to browser and found that Brotli reduces the size of final download package by 43% compare to gzip.

I first tried by setting up only Brotli and all modern browser download the compressed file. But when tried with IE11 (which doesn't support brotli), download original contents without any compression which impact performance.

To handle this, I kept both Gzip and Brotli on IIS. But now all browser downloads the contents only in Gzip format most probably because of the request header order where gzip comes first.

I want to make it conditional so that by default browser download the contents in Brotli format and if browser doesn't support it then switch to gzip format automatically.

Any idea how to do it?

<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>
1
This looks like a similar issue: stackoverflow.com/q/40156880/3962537Dan Mašek
Thanks. Do I need to put that entry in applicationHost.config file?NGR

1 Answers

1
votes

You can enable multiple compression schemes both Brotli and Gzip compression and set the compression scheme prioritization.

IIS ships a default compression scheme provider gzip, it is registered as the gzip scheme in applicationHost.config by default. But if you also want use the Brotli compression, you need to add iisbrotli.dll as the Brotli compression scheme provider in applicationHost.config. Add Brotli compression scheme

Regarding how to set Compression Scheme Prioritization, it is divided into two versions: IIS 10.0 Version 1803 or Above and Before IIS 10.0 Version 1803.

About IIS 10.0 Version 1803 or Above, the priority of each compression scheme is determined by its order in the collection of the element.

About before IIS 10.0 Version 1803, it prioritizes the compression scheme based on the scheme order appearing in the Accept-Encoding request header value, but IIS always prioritizes gzip over br for the typical scenario that the browser sets Accept-Encoding: gzip, deflate, br header in the request. A possible workaround is installing the URL Rewrite Module and configuring a rewrite rule to modify the Accept-Encoding header value. Enabling Multiple Compression Schemes