开发者

YUI Compressor + gzip causes Illegal Character error in jQuery

开发者 https://www.devze.com 2023-01-03 06:04 出处:网络
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:

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

精彩评论

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

关注公众号