YSlow Django 应用最佳实践,如何实现?
我有一个 django 1.1.1 应用程序,实际上正在开发中,在最佳实践中考虑我运行了 YSlow 测试(应用了 E 级规则集: YSlow V2 ),它推荐:
<块引用>“添加过期”标头的等级为 F
-共有 37 个静态组件,没有远期到期日期。
使用内容分发网络 (CDN) 的 F 级
-有 37 个静态组件不在 CDN 上。
使用 gzip 压缩组件的 F 级
-有 17 个纯文本组件应压缩发送
如何使用 Django 实现它?
更多上下文:Python 2.5,部署在 webfaction
示例:
<块引用>F 级,减少 HTTP 请求
此页面有 14 个外部 Javascript 脚本。尝试将它们合二为一。 此页面有 4 个外部样式表。尝试将它们合并为一个。
可以使用Django-Compress解决
I have an django 1.1.1 app, actually in developement, thinking in best practices I ran the YSlow test (Grade E Ruleset applied: YSlow V2 ) it recomends:
Grade F on Add Expires headers
-There are 37 static components without a far-future expiration date.
Grade F on Use a Content Delivery Network (CDN)
-There are 37 static components that are not on CDN.
Grade F on Compress components with gzip
-There are 17 plain text components that should be sent compressed
How can I implement it with Django?
More context: Python 2.5, deployment at webfaction
Example:
Grade F on Make fewer HTTP requests
This page has 14 external Javascript scripts. Try combining them into one.
This page has 4 external stylesheets. Try combining them into one.Can be solved with Django-Compress
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您列出的三个中,有两个可在 Web 服务器级别寻址。例如,在 Linux/Apache 中:
对于 gzip,编辑 /etc/apache2/mods-available/deflate.conf
对于 Expires 标头,首先需要启用 mod_expires:
然后需要为所需的 MIME 类型配置它:
Writeup on为什么我建议此处 12 小时。
最后一项 (CDN) 通常是您外包给 Akamai 等公司的内容。它也相当昂贵。
Of the three you listed, two are addressable at the web-server level. For example, in Linux/Apache:
For gzip, edit /etc/apache2/mods-available/deflate.conf
For Expires headers, first you need to enable mod_expires:
Then you need to configure it for the MIME types you want:
Writeup on why I recommend 12 hours here.
The last item (CDN) is typically something you outsource to someone like Akamai. It's also quite expensive.
我非常同意你的观点,蔡斯。我根据 Steve Souders 和 Nicholas Zakas 的工作开发了一些 django 程序。
我的标准做法是:
Nginx gzip 配置在 nginx.conf 中:
Nginx 远期过期标头:
它们唯一剩下的项目是图像上传,在远期过期后仍然可以使用,因为当图像更改时,文件名也应该更改。
使用这些技术,我创建了具有 3 个 http 请求的网站。页面呈现后,html 文件、页眉中的一个 CSS 请求和页脚中的一个 JS 请求。
I agree very much with you Chase. I've developed some django procedures based a lot on the work of Steve Souders and Nicholas Zakas.
My standard practices are:
Nginx gzip config in nginx.conf:
Nginx far futures expires header:
They only items left over are image uploads which can still be used with far future expires, because when the image changes the filename should change too.
Using those techniques I have produced sites with 3 http requests. The html file, one CSS request in the header, and one JS request in the footer after the page has rendered.
这些都与 Django 无关,因为 YSlow 指的是您网站上的静态资产 - JS、CSS 和图像。通过开发服务器提供这些服务必然会导致成绩不及格,但做得更好将取决于您如何配置最终提供这些服务的真实服务器。
None of these have anything to do with Django, since YSlow is referring to the static assets on your site - JS, CSS and images. Serving these through the development server is bound to lead to failing grades, but doing better will depend on how you configure the real server that ends up serving these.