Skip to content

Instantly share code, notes, and snippets.

@jreinke
Created April 29, 2013 21:19
Show Gist options
  • Save jreinke/5484860 to your computer and use it in GitHub Desktop.
Save jreinke/5484860 to your computer and use it in GitHub Desktop.
gzip static files when mod_gzip is not available
<Files *.js.gz>
AddType "text/javascript" .gz
AddEncoding gzip .gz
</Files>
<Files *.css.gz>
AddType "text/css" .gz
AddEncoding gzip .gz
</Files>
# 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]
find . -regex ".*\(css\|js\)$" -exec bash -c 'echo Compressing "{}" && gzip -c --best "{}" > "{}.gz"' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment