Fmdpa Posted December 16, 2010 Share Posted December 16, 2010 I'm attempting to enable the Deflate module on Apache. I already un-commented the line that loads the module .so file, but how do I make it work? I read the Apache documentation page, but it isn't clear on where to put it. It mentions the <Location /></Location> directive, so I assume it goes somewhere within the httpd.conf file...? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 16, 2010 Share Posted December 16, 2010 I read the Apache documentation page, but it isn't clear on where to put it.Where to put what? Link to comment Share on other sites More sharing options...
Fmdpa Posted December 17, 2010 Author Share Posted December 17, 2010 The <Directory /> directive in which all of the filters are enclosed. See here: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html Link to comment Share on other sites More sharing options...
Fmdpa Posted December 18, 2010 Author Share Posted December 18, 2010 All of the articles I read say what to put to enable compression, but not where to put it. For example, an article I just read said to uncomment the line so that mod_deflate.so loads. Then it said, "append the <Location ...> directive". Append to what? Do I put it in httpd.conf, and if so, where? .htaccess? I'm sure web hosting cpanels have an option to do this, but how do I do it manually? Link to comment Share on other sites More sharing options...
boen_robot Posted December 18, 2010 Share Posted December 18, 2010 The question is what are you trying to compress... enclose those directives in a kind of structure that makes sence to what you're trying to compress.So, if you want to compress all files but jp(e)g, gif and png and bmp images, you can do that with something like: <FilesMatch "\.(?!(jp(e?)g|gif|png|bmp))$">SetOutputFilter DEFLATE </FilesMatch> (Note: Unsure about the regex... in my configuration, I have a folder for images in which the compression is disabled, and that's it)And you put that right at the end of your httpd.conf file or .htaccess file.Alternatively, you might want to instead compress all non image MIME types instead, so that even images generated by PHP don't get compressed. You can do that like: FilterDeclare COMPRESSIONFilterProvider COMPRESSION DEFLATE resp=Content-Type !$image/FilterChain COMPRESSION (Note: Untested...)Again right at the end of your httpd.conf or .htaccess file. Link to comment Share on other sites More sharing options...
Fmdpa Posted December 18, 2010 Author Share Posted December 18, 2010 Thank you so much! It's incredible how much this helped download times. My (originally) 24 kb stylesheet was compressed to 5.5 kb. Script files also were compressed greatly. Would deflating images degrade their quality? Link to comment Share on other sites More sharing options...
Dilated Posted December 19, 2010 Share Posted December 19, 2010 Would deflating images degrade their quality?No. The files are served by the server, compressed, to browsers which can then decompress them once they receive them. The browser ends up with the same exact file in the end. Link to comment Share on other sites More sharing options...
boen_robot Posted December 19, 2010 Share Posted December 19, 2010 ... but the reason compression is usually disabled for images is because the reduction is really low (unless perhaps we're talking bmp...), and the time you'll save with those few bytes will be spent compressing and decompressing the content. With a reduction as great as from 24kb to 5kb, the compression and decompression time is well worth it. Link to comment Share on other sites More sharing options...
Fmdpa Posted December 21, 2010 Author Share Posted December 21, 2010 Yes, I realize that it is most effective for text-based files, but I had not thought that it might actually make loading images a bit slower. Maybe if I converted all images to a base64 string, compressed them, then decoded them it would save time. Link to comment Share on other sites More sharing options...
boen_robot Posted December 21, 2010 Share Posted December 21, 2010 Why?The browser still needs to see image bytes, and giving it anything else means it will take some time for it to get the content... same for the server.The problem image bytes can hardly be compressed is because they mostly lack patterns in them... their bytes are chaotic. Text compression works because every word in the text (or better yet - every repeated phrase) is placed in a "dictionary" by the compressor and a single byte mark is placed at each point from which there were previously few bytes. Higher compression will usually involve making a dictionary out of the byte marks and/or the dictionary itself and/or intertwining several patterns in a single byte mark with each few bits marking what would normally be a single byte and the rest describing a pattern variation, (e.g. first 4 bits are dictionary word, and the next 4 bits say that the same dictionary entry repeats that many times; I don't know if any real compressor uses this particular approach, but it's usually something in the same spirit).BMP is an exception because in it, the bytes are "as is". If you see (for example) one shade of green repeated across 1002 pixels in the image, that's 1002 (pixels) x 3 (bytes per pixel) = 3006 bytes that can be reduced to at least 1002 / 3 = 334 bytes, along with 4 bytes for the dictionary entry.To put this in another way, compression doesn't work on images because images are by their nature already compressed. Link to comment Share on other sites More sharing options...
Fmdpa Posted December 21, 2010 Author Share Posted December 21, 2010 Thanks for the explanation. I wasn't quite sure how compression worked. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.