{"id":28,"date":"2007-12-12T22:56:57","date_gmt":"2007-12-12T22:56:57","guid":{"rendered":"http:\/\/installingcats.com\/2007\/12\/12\/mod_deflate-gzip-compression-http11-vs-10\/"},"modified":"2007-12-12T22:56:57","modified_gmt":"2007-12-12T22:56:57","slug":"mod_deflate-gzip-compression-http11-vs-10","status":"publish","type":"post","link":"https:\/\/installingcats.com\/2007\/12\/12\/mod_deflate-gzip-compression-http11-vs-10\/","title":{"rendered":"mod_deflate gzip compression http\/1.1 vs. 1.0"},"content":{"rendered":"

If that title makes no sense to you, well… that’s good, cause you probably didn’t spend the last three hours trying to figure out why gzip compression is not working on Javascript files being served from your Apache 2.x web server.<\/p>\n

For those of you unlucky enough to understand what I’m talking about (and thus stuck scratching your head at why Apache 2.x with mod_deflate is not compressing javascript, css, etc. files… the reason is (drum roll please): gzip compression is handled transparently by all modern browsers. Furthermore, HTTP\/1.1 enabled browsers will check their cache to see if a copy of the file requested is in the cache and will not download the same file from server if present locally. Apache still receives a request for a file that is in cache, but only to check that the file version is the same, and if it is the same, Apache will not serve the file<\/em>. This is the key to understanding why Apache logs report no compression on files served to a HTTP 1.1 compliant browsers… it’s cause the file was not actually sent to the requesting browser.<\/p>\n


\n\"GET \/javascripts\/prototip.js HTTP\/1.1\" -\/- (-%)
\n\"GET \/javascripts\/prototip.js HTTP\/1.1\" 2649\/9002 (29%)
\n\"GET \/favicon.ico HTTP\/1.1\" -\/- (-%)
\n\"GET \/javascripts\/prototip.js HTTP\/1.1\" 2649\/9002 (29%)
\n\"GET \/favicon.ico HTTP\/1.1\" -\/- (-%)
\n<\/code><\/p>\n

In the above snippet of a mod_deflate log, the first line is Apache “serving” the prototip.js file, with 0Bytes [compressed] \/ 0 Bytes [uncompressed] (0% compression rate). The reason? The file is cached at the browser and thus the file is not actually sent.
\nThe second line is after clearing the browser cache<\/strong>. It shows that prototip.js was sent to the browser as a 2649 Byte compressed file from an original uncompressed 9000 Byte file, which gives a compression rate of 29%. The favicon.ico file (for the little icons your see beside your site name in browser window tabs) is sent uncompressed due to it not being one of the file types we specified in http-vhosts.conf, therefore, no compression was applied to the file.<\/p>\n

There is a good chance that I’m talking straight outta my butt on this. If you know better than I on this subject, please do leave a comment and let me know what’s really going on.<\/p>\n

For reference, here is the pertinent part of my http-vhosts.conf file, with comments\/junk removed.
\n
\n78 AddOutputFilterByType DEFLATE text\/html text\/plain text\/css
\n80 AddOutputFilterByType DEFLATE text\/javascript application\/x-javascript
\n82 BrowserMatch ^Mozilla\/4 gzip-only-text\/html
\n83 BrowserMatch ^Mozilla\/4.0[678] no-gzip
\n84 BrowserMatch bMSIE !no-gzip !gzip-only-text\/html
\n85 DeflateFilterNote Input input_info
\n86 DeflateFilterNote Output output_info
\n87 DeflateFilterNote Ratio ratio_info
\n88 LogFormat '\"%r\" %{output_info}n\/%{input_info}n (%{ratio_info}n%%)' deflate
\n89 CustomLog \/var\/www\/test.net\/shared\/log\/myapp_deflate_log deflate
\n<\/code><\/p>\n

I know you’re itchin’ for some good old HTTP Compression RFC (Request For Comments) 2616 reading so here it is<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

If that title makes no sense to you, well… that’s good, cause you probably didn’t spend the last three hours trying to figure out why gzip compression is not working on Javascript files being served from your Apache 2.x web server. For those of you unlucky enough to understand what I’m talking about (and thus […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[64,65,66,67],"_links":{"self":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/posts\/28"}],"collection":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":0,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}