How To Improve Django Performance

Anthony Zhan| 2013-08-02 Web Development, Tutorials Comments( 0 )

Django help you build your website rapidly with least code duplication. Then, after you finish the developing work for your site, next thing you should consider is how to optimize it to serve more user. This article talk about the main areas to improve django performance.

Enable Cache

Cache is important for every site no matter what framework used. The lucky thing is django provide a quite simple way to enable cache. Although Django supports many cache backends, I highly recommended your choose memcached which has proved to be a high-performance distributed memory object caching system. Don't be afraid of the word "distributed", memcached is extremely simple for setup and deploy consider other distributed system. Check more information at Django’s cache framework.

Merge & Minify Media

Put different js and css in splitted files makes the code more readable, while, it may also cause too many request to the server. So you'd better merge and minity them on the product environment. Django itseft has no tools for you to do this, you'll need a 3rd party app, called django-compress. It provides an automated system for compressing CSS and JavaScript files. There is also a DEBUG mode in django-compress, which means you can still debug and edit your source files while coding, and when deploying to production, the compressed files will be automatically generated.

Enable GZip Module

Enable gzip can speed up pageload. It's said that gzip can reduce the content size by 70% ~ 80%. Of course, enable gzip take a little extra CPU and memory cost, so you'll consider which is more important. However in most cases, enable gzip is a better choice. To enable gzip you can use apache mod_deflate module in your Django hosting environment, or, simple add "django.middleware.gzip.GZipMiddleware" into your MIDDLEWARE_CLASSES in

Use separate domains for static and media files

Create subdomains for static files media files. Do not forget add their url and path to (STATIC_URL, STATIC_ROOT, MEDIA_URL, MEDIA_ROOT).

Code Level Optimization

An effective code make more senses than the aboving ways. However, how to write effective codes is not include in this article. Your can find some tips at Database access optimization.

Tagged with:

We hope webmasters to share and promote the good articles ,Please click herecontribute

You need to log in to commentLogin|Register

Be the first to comment!