mod_deflate 与 Django GZipMiddleware,使用哪一个进行部署?

发布于 2024-07-27 01:26:18 字数 122 浏览 5 评论 0原文

我们正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

病女 2024-08-03 01:26:19

我肯定会选择 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.

纸伞微斜 2024-08-03 01:26:18

你可能应该测试一下才能确定,但​​如果我猜的话,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.

薄凉少年不暖心 2024-08-03 01:26:18

这取决于。 如果您在 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.

浪推晚风 2024-08-03 01:26:18

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文