Making Django development server faster at serving static media

I'm using the Django runserver for developing my application (obviously), but it takes 10 seconds to completely load a page because the development server is very, very slow at serving static media.

Is there any way to speed it up or some kind of workaround? I'm using Windows 7.


Consider using mod_wsgi instead, and having httpd handle the static media.

Development server is simple unsafe single-threaded application, so you cannot do much.

One trick you could try is to redirect /site_media to second development server, but this is ugly and probably wouldn't help that much. So you could try bundling/compressing multiple assets into one css/js (e.g. using YUI Compressor).

And in any case, you should have separate static media server, that can serve multiple assets at once.

Install Firefox (if you haven't already), and install the Firebug Add-On. Restart your browser. In the lower-right corner click the "bug" icon and make sure that in the "Network" tab (it's a dropdown) of the Firebug panel that opens at the bottom of the browser, the network monitor is active.

Now with the network tab of Firebug open, open your Django-generated page that you observed to load slowly. Take a look at the timeline bars. You'll notice that the colored fragment(s) of each bar indicate(s) the reason for each request's total "load" time. Violet, for instance, means that actually the browser is waiting for the server to generate the response. Gray means it's receiving content. And so on. Hovering over the bars will display a color legend.

With Firebug's network monitor you should be able to pinpoint how exactly your browser and/or server are spending their 10 seconds.

Run lighttpd to serve the static content and use the MEDIA_URL to point the pages at the lighttpd server that servers the static stuff.

Lightning fast ans easy on resources when using NGINX for serving static and media files. Here's how it goes. However, you'll need to adapt some paths according to your use case and system. But I think this will get you started:

1) Download NGINX for your system, in your case Windows:

2) Unpack the zip file. Here's how your NGINX config file may look like. This file lives inside nginx/conf/:

worker_processes 1;

events {
    worker_connections  1024;

http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    # root path to your project
    # use "..." if spaces are in the path
    # you may add a drive letter if required, e.g. root c:/foo
    # use / instead of \. It's simpler and works
    root /example/path/django/project/;
    server {
        # any free port number will do; Django dev server usually runs on port 80
        listen 8000 default;
        server_name localhost; # or

3) Start NGINX by calling the nginx.exe - no options needed.

4) Tweak your Djnago project's file:

    STATIC_URL = 'http://localhost:8000/static/'
    # against Django recommendation, I often still use the static
    # directory for user uploads; old-style Django ;-)
    MEDIA_URL = 'http://localhost:8000/static/uploads/'

Now, the static URLs in Django should look something like this: http://localhost:8000/static/js/base.js

... 5) Stop the server by calling:

taskkill /f /IM nginx.exe

Well, that's it. I typed this quickly, so just let me know if anything's unclear or not working for you. I may improve this answer accordingly.

Need Your Help

java.lang.NullPointerException when i run my unit test - mockito

spring-mvc mockito spring-test spring-test-mvc springmockito

i have a spring mvc application and using mockito for my unit test.I keep getting null pointer exception when i run my unit test. :(

get TreeNode by number

java data-structures heap binary-tree binary-heap

I am creating a heap from a binary tree in java. My implementation looks like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.