02-24-2012, 06:59 AM
Hurray for jerry-rigging things. I ended up just compressing all the .js and .css files into their own .gz file, then adding handlers for the resulting files, along with a rewrite to use the pre-zipped ones instead. It should also lower the load on the server and be even faster than having it deflate the file every time. ;3
One liner to gzip all css and js files Wrote:find . -regex ".*\(css\|js\)$" -exec bash -c 'echo Compressing "{}" && gzip -cf --best "{}" > "{}.gz"' \;
.htaccess addition Wrote:
AddType "text/javascript" .gz
AddEncoding gzip .gz
AddType "text/css" .gz
AddEncoding gzip .gz
RewriteEngine on
#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
#make sure there's no trailing .gz on the url
ReWriteCond %{REQUEST_FILENAME} !^.+\.gz$
#check to see if a .gz version of the file exists.
RewriteCond %{REQUEST_FILENAME}.gz -f
#All conditions met so add .gz to URL filename (invisibly)
RewriteRule ^(.+) $1.gz [QSA,L]