HTTP Compression with Apache besides Deflate and gzip? - apache

I have a server, and I want to set up HTTP Compression. How can I use another compression type for HTTP Compression on my own server? I want to experiment with lzop, lzma or xz, for example.
I know I can use gzip and deflate with mod_gzip and mod_deflate, but I am wondering if there are options to expand this selection.

There are only three algorithms officially supported: deflate (zip), compress (lzw) and gzip. You can compress all you want, but no browser won't be able to read it.
Source: RFC 2616, section 3.5.
You can still offer a download of e.g. a bzip2 file, but I guess that's not what you want.

Related

Deflate compress a string in mule

I wanted to know if there's any way to compress a string using deflate algorithm in Mule 4. I am aware of Kryo serialization framework in mule, but I am not sure of the correct configuration and how to verify the compressed string.Any code snippet of the same will be greatly useful.
Thanks in advance.
The Compression Module offers zip and gzip compression/decompression operations. Both formats use the deflate algorithm.
If you don't the gzip or zip formats and only want the deflate compression, then you probably need to implement it yourself in a Java class or create your own module, and call from there a Java implementation of Deflate, like https://docs.oracle.com/javase/8/docs/api/java/util/zip/Deflater.html.

How does Apache handle images/flash when deflate mode is on

I'm thinking of enabling deflate mode on Apache. I'm curious how does Apache deal with images or flash files when deflate is on? Does it try to compress images and flash files as well?
Sure. If you don't set any filters the server will compress everything if the client supports the compression.
If you use the line from the documentation:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
That would just compress text files with that content types.
"Image file formats supported by the web, as well as videos, PDFs and
other binary formats, are already compressed; using gzip on them won't
provide any additional benefit, and can actually make them larger. To
compress images, see Optimize images."
https://developers.google.com/speed/docs/best-practices/payload#GzipCompression

Why are major web sites using gzip?

I just searched about gzip and Deflate, and found out that Deflate is better.
GZip or Deflate for HTTP compression
Why use deflate instead of gzip for text files served by Apache?
Is there any performance hit involved in choosing gzip over deflate for http compression?
Deflate compression browser compatibility and advantages over GZIP
But when I checked the response headers of Google, Facebook and StackExchange, all of them were using GZIP. Why do they use gzip instead of Deflate?
It is apparently due to a misunderstanding resulting from the choice of the name "Deflate". The http standard clearly states that "deflate" really means the zlib format:
The "zlib" format defined in RFC 1950 [31] in combination with
the "deflate" compression mechanism described in RFC 1951 [29].
However early Microsoft servers would incorrectly deliver raw deflate for "Deflate" (i.e. just RFC 1951 data without the zlib RFC 1950 wrapper). This caused problems, browsers had to try it both ways, and in the end it was simply more reliable to only use gzip.
The impact in bandwidth and execution time to use gzip instead of "Deflate" (zlib), is relatively small. So there we are and there it is likely to remain.
The difference is 12 more bytes for gzip and slightly more CPU time to calculate a CRC instead of an Adler-32.

Can mod_deflate compress the output depending on the "Host" header in the Request Headers?

Can mod_deflate compress the output depending on the "Host" header in the Request Headers?
As far as I understand based on the documentation, it is usually done by looking at the User-Agent etc. in the configuration.
I could not find any example in doc that says -
If Host: header is x.y.z then do compression. Else don't do compression.
Thanks!
From the manual:
Compression is implemented by the DEFLATE filter. The following directive will enable compression for documents in the container where it is placed:
SetOutputFilter DEFLATE
Didn't test it, but "container" should include "<VirtualHost>", so just place it only in those VHs you want to deliver compressed responses.

Enable mod_deflate to send Content-Encoding: gzip

EDIT I have found that the problem is actually php minify. This was sending the deflated content instead of Apache. I'll find more on this.
According to High Performance Web Sites, if I enable mod_deflate in Apache 2.x, by adding the following line, it should send gzipped/delfated content: -
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript
The book also says that gzip is more effective than deflate.
I have enabled in httpd.conf by adding the same line. But Apache sends Content-Encoding: deflate.
I tested with CURL using: -
curl -i -H "Accept-Encoding: gzip" "http://192.168.1.33/s.js" >> e:\curl_log.txt
It returns 'gzipped' content. But when I send the command: -
curl -i -H "Accept-Encoding: gzip, deflate" "http://192.168.1.33/s.js" >> e:\curl_log.txt
It returns 'deflated' content.
So, if the browser supports both deflated and gzipped, Apache send deflated. How to tell Apache to prefer gzip over deflate?
FYI: -
I could not find anything in:
http://httpd.apache.org/docs/2.0/mod/mod_deflate.html.
There is no occurrence of no-gzip in
the Apache conf.
Server: Apache/2.2.9 (Win32) PHP/5.2.6
FF sends request header as: "Accept-Encoding: gzip, deflate"
As I see the cause was already found. To further on help getting out of possible confusions:
mod_deflate despite its name is currently only supporting gzip.
gzip is more "effective" because of the following
deflate - despite its name the zlib compression (RFC 1950) should be used (in combination with the deflate compression (RFC 1951)) as described in the RFC 2616. The implementation in the real world however seems to vary between the zlib compression and the (raw) deflate compression[3][4]. Due to this confusion, gzip has positioned itself as the more reliable default method (March 2011).
gzip and zlib are file/stream formats that by default wrap around deflate and amongst other things add a checksum which make them more secure and a little slower. The increase in size on the other hand should not be of any concern.
Also see HTTP_compression - Wikipedia
deflate would be more "efficient" (Frequently Asked Questions about zlib - What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings)
See http://httpd.apache.org/docs/2.0/mod/mod_deflate.html for all the gory details -- are you sure you don't have occurrences of no-gzip elsewhere in the configuration? What happens as you vary your "browser", e.g. by using wget with various values for -U?
I suspect whatever you're using to test is not sending ...
Accept-Encoding: gzip
... in the request header.