views:

310

answers:

2

Hi,

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

A: 

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.

Daniel Roseman
+3  A: 

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

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

For Expires headers, first you need to enable mod_expires:

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

Then you need to configure it for the MIME types you want:

# 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"

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.

Chase Seibert