RewriteEngine on
RewriteOptions Inherit
#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} (gzip.*)
#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 and set environment variable
RewriteRule ^(.+) $1.gz [E=SERVE_AS_GZIP:yes,L]
#Override content-type
ForceType text/javascript
#Set Content-Encoding if SERVE_AS_GZIP is set
Header set Content-Encoding gzip env=SERVE_AS_GZIP