views:

175

answers:

1

When I minify jquery using YUI compressor, it works fine. When I then add gzip compression (and serve this version via mod rewrite), the gzipped version throws this error:

illegal character in jquery.min.js on line 1

Line 1 is:

�������M�����������s�8�0�?�!sz�dKr�=�

This results in a "jquery is not defined" error. I am using the following rewrite rules to serve up the gzipped versions:

#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 filename (invisibly)
RewriteRule ^(.+) $1.gz [L] 

I can't find any references to this happening to anyone else. Thoughts?

P.S. - it looks like this same question was asked on the jQuery forums in 2008. It has 278 views, but no answer: http://forum.jquery.com/topic/how-to-reference-jquery-1-2-6-min-js-when-zipped-with-gzip

A: 

If I had to guess, I would say Apache is already gzipping your JS file, and your rewrite leads to the request being doubly compressed.

Remove the rewrite rules and take a look at the jQuery file in Firebug. You will see there whether it is already being served compressed.

Pekka
Turns out you're right! But it's the YSlow plugin for Firebug that told me so, not Firebug itself. Thanks!
lo_fye