tools.gzip 似乎不会压缩cherrypy 中的内容
我正在 Chrome 和 Firefox 下使用 Yslow 工具审查我的开发网站,建议之一是我对适当的内容进行 gzip 压缩。作为起点,我刚刚将“tools.gzip.on = True”添加到我的[/]配置中。我知道配置文件和块正在被正确解析,因为我还在响应标头中添加了禁用缓存的选项,因为我在开发站点时经常更改文件。我在响应中看到“Expires”和“Pragma: no-cache”标头。
由于某种原因,即使在更改配置文件(并重新启动进程,这不是绝对必要的)之后,Yslow 仍然报告我没有使用 gzip。我也一直在使用 wget 并且没有看到 Content-Encoding 标头。
谁能建议我还能如何验证正在发生的事情?我想知道这个问题是否是因为忽略了 gzip 设置,或者是 Yslow 只是弄错了事实。我以前从未遇到过 Yslow 的问题,所以我倾向于前者。
我要补充的是,Yslow 仅报告我的外部 CSS 和 JavaScript 文件(由相同的cherrypy 进程提供)需要压缩,即使“wget -S”显示的标头甚至在主目录上也不显示 gzip 编码页面本身(这是动态内容)。
我尝试将“tools.gzip.on = True”添加到我的[/css]和[/js]块中,并且我还尝试在所有相同的块中设置“tools.encode.on = True”,我想也许必须启用编码才能使 gzip 工作。
提前致谢。
I'm reviewing my development site with the Yslow tool under Chrome and Firefox, and one of the suggestions is that I gzip appropriate content. As a starting point I just added "tools.gzip.on = True" to my [/] configuration. I know the configuration file and block are being parsed correctly, because I also added options to disable caching in the response headers, since I'm changing the files frequently as I develop the site. I am seeing "Expires" and "Pragma: no-cache" headers in my responses.
For some reason, even after changing the configuration file (and restarting the process, which isn't strictly necessary), Yslow still reports that I'm not using gzip. I've also been using wget and see no Content-Encoding header.
Can anyone suggest how else I might verify what's going on? I'm wondering whether the issue is cherrypy ignoring the gzip setting, or Yslow just getting its facts wrong. I've never had trouble with Yslow before, so I lean toward the former.
I'll add that Yslow is only reporting that my external CSS and JavaScript files (served by the same cherrypy process) need to be compressed, even though the headers shown by "wget -S" don't show gzip encoding even on the main page itself (which is dynamic content).
I've tried adding "tools.gzip.on = True" to my [/css] and [/js] blocks, and I've also tried setting "tools.encode.on = True" in all of the same blocks, thinking perhaps encoding had to be enabled for gzip to work.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cherrypy.lib.gzip 的 3.2 文档字符串:
我的钱花在 MIME 类型上,因为你提到了 JS 和 CSS。您可以这样更改:
在 CherryPy 3.2+ 中,您可以将其缩短为:
The 3.2 docstring for cherrypy.lib.gzip:
My money's on the MIME type, since you mention JS and CSS. You can change that thusly:
In CherryPy 3.2+, you can shorten that to:
为了使这项工作适用于 Javascript,我还必须包含“application/*”作为 mime_type。
我的配置的相关部分如下所示:
To make this work for Javascript I had to also include 'application/*' as a mime_type.
The relevant portion of my config looks like this: