gpt4 book ai didi

django - YSlow Django 应用最佳实践,如何实现?

转载 作者:行者123 更新时间:2023-12-02 08:10:35 25 4
gpt4 key购买 nike

我有一个 django 1.1.1 应用程序,实际上正在开发中,在最佳实践中思考我运行了 YSlow 测试(应用了 E 级规则集:YSlow V2 ),它推荐:

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

如何使用 Django 实现它?

更多上下文:Python 2.5,在 webfaction 部署

示例:

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 服务器级别进行寻址。例如,在 Linux/Apache 中:

对于 gzip,编辑/etc/apache2/mods-available/deflate.conf

<IfModule mod_deflate.c>  
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascript text/javascript text/css application/javascript
</IfModule>

对于 Expires header ,首先需要启用 mod_expires:

>cd /etc/apache2
>sudo ln -s ../mods-available/expires.load mods-enabled/expires.load

然后您需要将其配置为您想要的 MIME 类型:

# edit /etc/apache2/sites-available/default  
ExpiresActive On
ExpiresByType text/css "access plus 12 hours"
ExpiresByType application/javascript "access plus 12 hours"
ExpiresByType image/png "access plus 12 hours"
ExpiresByType image/gif "access plus 12 hours"

写下为什么我建议 12 小时 here

最后一项 (CDN) 通常是您外包给像 Akamai 这样的人的东西。价格也相当昂贵。

关于django - YSlow Django 应用最佳实践,如何实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1693584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com