开发者

YUI Compressor + gzip causes Illegal Character error in jQuery

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 v开发者_JS百科ersion 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜