Reputation: 3528
Google says Zopfli gives a better gzip-functionality and it's compatible with all browsers (decompression is the same, compression takes a lot longer, but you get an additional 5-10% smaller static files footprint)
So, i know you can do this for gzip compression of static files:
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
dynamicCompressionDisableCpuUsage="90"
dynamicCompressionEnableCpuUsage="80"
maxDiskSpaceUsage="100" minFileSizeForComp="2700"
noCompressionForRange="true"
sendCacheHeaders="false"
staticCompressionDisableCpuUsage="100"
staticCompressionEnableCpuUsage="80" >
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4"
staticCompressionLevel="7" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="application/xml" 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/json" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/rss+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="application/xml" enabled="true" />
<add mimeType="image/svg+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
...
But how would you implement Zopfli instead of the standard GZip-library in web.config?
Upvotes: 5
Views: 3417
Reputation: 1311
This question was posed over a year ago, but a few things have changed, and this may benefit future landers on this page:
First, it's important to highlight that zopfli creates gzip files. So at the level of analysis implied in the web.config (or .htaccess), there wouldn't be any zopfli-awareness.
Because it is at least an order of magnitude slower than DEFLATE/typical gzipping, it's not in the running for on-the-fly compression, which is what IIS and Apache are doing. It's unlikely we'll ever see the zopfli algorithm implemented on a server for on-the-fly compression.
You can use zopfli in advance, to pre-compress your assets before deploying them on the server. One way you can now do this is via a node.js package: node-zopfli.
And now Telerik has a neat tool that will tell you if your assets would benefit from zopfli, and by how much.
The zopfli source code library is here.
Pigz is one implementation, and Krzysztof Kowalczyk has ported it to Windows.
Upvotes: 1
Reputation: 4873
Zopfli compression is slow, so I would recommend compressing static files before uploading them, even better use a CDN and Zopfli for static files.
If you are using .net take a look at a library I recently published on github
https://github.com/echovoice/libzopfli-sharp
I derived the Stream class, usage is simple
using (MemoryStream compressStream = new MemoryStream())
using (ZopfliStream compressor = new ZopfliStream(compressStream, ZopfliFormat.ZOPFLI_FORMAT_DEFLATE))
{
compressor.Write(uncompressed, 0, before);
compressor.Close();
compressed = compressStream.ToArray(); // here is the compressed data
}
This library is available on Nuget as libzopfli-sharp, https://www.nuget.org/packages/libzopfli-sharp
So it would be possible to use this class to create and register a filter for IIS, but that would be a bad idea and make website performance worse.
Upvotes: 5
Reputation: 112472
You can get pigz for static compression, which is a parallel gzip replacement that includes zopfli compression at level 11.
zopfli would likely not be beneficial for dynamic compression, since it will take much longer to compress out that extra few percent of data than it would take to simply transmit that extra few percent of data.
zopfli is intended for those cases where something is compressed once and then sent or stored many times and decompressed many times. Not for cases where something is compressed once and decompressed once.
Upvotes: 6
Reputation: 456
That is not possible yet! You should be able to precompress any files you have though manually.
Currently zopfli is not a dll/library so you can't use it to dynamically compress things unless you were able to write a script to handle it but that would be outside the scope of your question.
I think it may be possible in the future once zopfli is converted to a library to either drop it in place of gzip.dll or write a wrapper to do so.
Upvotes: 0