How to implement zopfli for better gzip compression?

Google says Zopfli gives the best gzip functionality and compatibility with all browsers (decompression is the same, compression takes much longer, but you get an additional 5-10% smaller size of static files)

So, I know that you can do this to compress gzip 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?

+4
source share
4 answers

Zopfli compression is slow, so I recommend compressing static files before downloading them, it is even better to use CDN and Zopfli for static files.

If you are using .net, take a look at the library I recently posted on github

https://github.com/echovoice/libzopfli-sharp

I got a Stream class, using 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

Thus, you could use this class to create and register a filter for IIS, but this would be a bad idea and would degrade site performance.

+4
source

You can get pigz for static compression, which is a parallel gzip replacement that includes zopfli compression at level 11.

zopfli would probably not be useful for dynamic compression, since it would take a lot longer to compress this extra percent of data than it would just take to transfer this extra percent of data.

zopfli is designed for cases when something is compressed once, and then sent or stored many times and multiplied many times. Not for cases when something is compressed once and unpacked once.

+6
source

This question was asked more than a year ago, but some things have changed, and this may benefit future airfields on this page:

  • First, it’s important to emphasize that zopfli creates gzip files . Thus, at the analysis level, which is implied in the web.config (or .htaccess) file, there would be no zopfli awareness.

  • Since it is at least an order of magnitude slower than DEFLATE / typical gzipping, it does not work for compression on the fly, which is what IIS and Apache do. It is unlikely that we will ever see the zopfli algorithm implemented on the server for compression on the fly.

  • You can use zopfli in advance, precompile your assets before deploying them to the server. One way to do this is with the node.js package: node-zopfli .

And now Telerik has a neat tool that will tell you if your assets will benefit from zopfli and how much.

The zopfli source code library is here.

Pigz is one implementation, and Krzysztof Kowalczyk ported it for Windows .

+1
source

This is not yet possible! You should be able to pre-compress any files you have manually.

Currently, zopfli is not a dll / library , so you cannot use it to dynamically compress things unless you can write a script to handle this, but that does not go beyond your question.

I think this is possible in the future when zopfli is converted to a library to either remove it instead of gzip.dll or write a wrapper for this.

0
source

All Articles