When using javascript in your website, many recommend "compressing" the javascript - that is, get all the extraneous whitespace out of it. the idea is that there is less for the browser to download before actually executing the script. I see lots of stats of different javascript shrinkers of how much they shrink the filesize, but how much does that actually help in user experience? I suppose it really depends on the size of your js files and how speedy the user's link is.
Let's assume for the moment that it does make a difference. Editing a js file that has been shrunk is painful to say the least. It is just not practical, so you end up keeping the original version that you make your edits to, and then after you make edits you reshrink it into the shrunk file version. That is also a pain in the ass.
So I figure, why not use mod_deflate? It compresses the outgoing stream of stuff that http is sending from your server. That seems to achieve the overall goal that shrinking the js file is doing plus you also get to shrink everything else! We really only want to compress text stuff, though. There's no point in spinning the cpu trying to compress a jpeg. So, we also have to use mod_filter. Here's what I came up with based on what the apache docs and google told me:
<IfModule mod_filter.c>
<IfModule mod_deflate.c>
FilterDeclare compression CONTENT_SET
FilterProvider compression DEFLATE Content-Type $text/
FilterProvider compression inflate req=Accept-Encoding !$gzip
Filterchain compression
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/apache2/deflate_log deflate
</IfModule>
</IfModule>
Those last few lines allow you to log what mod_deflate is doing. You can drop them if you like.
Comments
Post new comment