mod_deflate 与 Django GZipMiddleware,使用哪一个进行部署?
我们正在使用 Apache 2.2 + mod_wsgi 部署 Django 应用程序。 我们应该在 Apache 中启用 mod_deflate 还是使用 Django 的 GZipMiddleware? 哪个选项表现更好?
We're deploying Django apps with Apache 2.2 + mod_wsgi. Should we enable mod_deflate in Apache or use Django's GZipMiddleware? Which option performs better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我肯定会选择 mod_deflate,假设你有 apache 直接提供的静态 css 和 js 文件,并且也可以压缩。
I would definitely go with mod_deflate, on the assumption that you have static css and js files which apache is serving directly and can also be compressed.
你可能应该测试一下才能确定,但如果我猜的话,mod_deflate 对于完全绕过 Django 的请求会更好(比如应该单独部署的压缩静态资源,即媒体)。
对于 Django 响应已经生成的内容,这可能是一个难以抉择的问题——无论哪种情况,都将由本机代码进行压缩。
You should probably test to know for sure, but if I were to guess, mod_deflate would be better for requests that totally bypass Django completely (like zipped up static resources that should be deployed separately i.e. media).
For things that are already generated by Django responses, it's probably a toss-up -- in either case it would be native code doing the zipping.
这取决于。 如果您在 Apache 中启用它,那么它也将用于静态内容(例如 CSS、Javascript、图像); 但一些静态内容(如 JPG、GIF、SWF)无论如何都可以得到很好的压缩。
It depends. If you enable it in Apache, then it will also be used for static content (e.g. CSS, Javascript, images); but some static content (like JPG, GIF, SWF) is pretty well compressed anyway.
mod_deflate 是一个更好的选择,因为它允许您选择压缩哪些内容类型(默认为 html、css 和 js)。
GZipMiddleware 非常幼稚,会尝试压缩任何内容并仅检查结果是否小于原始响应。 如果您以这种方式提供图像,那么每个请求的性能都会受到影响,而收益为零。
mod_deflate is a better choice because it allows you to choose which content types are compressed (defaults to html, css and js).
GZipMiddleware is very naive and will try to compress anything and just check if the result is smaller than the original response. If you're serving images that way you will take the performance hit for each request with 0 benefit.