YUI 压缩器 + gzip 在 jQuery 中导致非法字符错误
当我使用 YUI 压缩器缩小 jquery 时,它工作得很好。 然后,当我添加 gzip 压缩(并通过 mod 重写提供此版本)时,gzip 压缩版本会抛出此错误:第
1 行 jquery.min.js 中的非法字符
第 1 行是:
��������M� ����������s�8�0�?�!sz�dKr�=
� 这会导致“jquery 未定义”错误。 我正在使用以下重写规则来提供 gzip 压缩版本:
#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]
我找不到任何其他人发生这种情况的参考。 想法?
PS - 看起来 2008 年 jQuery 论坛上也提出了同样的问题。它有 278 次浏览,但没有答案:http://forum.jquery.com/topic/how-to-reference-jquery-1-2- 6 分钟 js-when-zipped-with-gzip
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我不得不猜测,我会说 Apache 已经对您的 JS 文件进行了 gzip 压缩,并且您的重写导致请求被双重压缩。
删除重写规则并查看 Firebug 中的 jQuery 文件。您将在那里看到它是否已经被压缩。
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.