YSlow Best practices with Django applications, how to implement them?

I have a django 1.1.1 application, actually in development, thinking of best practices. I tested the YSlow test (used by Erade E: ESlow V2), it recommends:

Grade F on Addition Expires Headers

     

- There are 37 static components with no expiration date.

     

Grade F on the use of a content delivery network (CDN)

     

- There are 37 static components that are not on the CDN.

     

Estimating F on gzip compression components

     

- There are 17 simple text components that should be sent compressed

How can I implement it using Django?

More context: Python 2.5, deployment in webfaction

Example:

Grade F on Make Less HTTP Requests

     

14 Javascript. .    4 . .

     

Django-Compress

+3
3

-. , Linux/Apache:

gzip /etc/apache 2/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 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 .

(CDN), , - Akamai. .

+3

. , .

:

  • django-mediagenerator, :
    • JS CSS
    • JS google CSS YUICompressor
    • ( ) . , 10 .
  • CSS.
  • , base64 CSS ( )
  • , ( , )
  • Nginx gunicorn

Nginx gzip config nginx.conf:

gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 64 16k;
gzip_disable "MSIE [1-6].(?!.*SV1)";

Nginx :

location /media/ {
    alias   /home/domains/example.com/project/_generated_media/;
    expires 10y;
    add_header Cache-Control public;
}   

- , , .

, HTTP-. html, CSS JS .

+2

Django, YSlow - JS, CSS . , , , .

0
source

Source: https://habr.com/ru/post/1722210/


All Articles