Opened 7 years ago

Closed 7 years ago

#8409 closed (fixed)

Django built-in server is very slow with Firefox browser when serving admin media

Reported by: andylowry Owned by: nobody
Component: HTTP handling Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Firefox (v3.0.1) with default settings is taking a very conservative view on cacheability of admin media files served by the Django built-in server in django.core.servers.basehttp.py. This can be dramatically improved by arranging for AdminMediaHandler class to provide Last-Modified headers in its responses. Without this change, IE outperforms Firefox on admin pages by a big margin (apparently its heuristics for cache expiry in this case are far looser).

Change History (7)

comment:1 Changed 7 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

The dev server really isn't built for speed.

comment:2 Changed 7 years ago by anonymous

  • Has patch set
  • Resolution invalid deleted
  • Status changed from closed to reopened

I understand that it's not built for speed, but the changes are trivial, and it makes a huge difference (1-second page load vs. about 10 seconds for a not terribly complicated admin page!). I'm sure the dev server gets used very extensively, especially since the tutorial and two different projects books both walk through how to use it (albeit with caveats). I'm reopening this because I think this is such a trivial change with a relatively big payoff that it's worth more serious consideration. But I won't reopen again if I haven't changed your mind this time.

Here are my changes (3 lines added to existing code):

At top of basehttp.py:

    import stat

Later, in the __call__ method:

                status = '200 OK'
		mtime = os.stat(file_path)[stat.ST_MTIME]
                headers = {'Last-Modified': http_date(mtime) }
                mime_type = mimetypes.guess_type(file_path)[0]

comment:3 Changed 7 years ago by Piotr Lewandowski <django@…>

  • Component changed from Uncategorized to HTTP handling

comment:4 Changed 7 years ago by marcusl

I second this. I have to switch between IE and FireFox when developing Django, because IE is fast and FireFox has FireBug.
The difference is that IE is instant and FireFox has a 1-2 second delay (when browsing my regular pages, not the admin), which is enough to impair me a bit.

I applied the patch and it didn't help all the way, but a little bit.

comment:5 Changed 7 years ago by adrian

andylowry: Thanks for bringing this up. I'm working on a fix. One thing I should note is that the solution is a bit more complicated than setting the Last-Modified header -- we also have to check the HTTP_IF_MODIFIED_SINCE header.

comment:6 Changed 7 years ago by adrian

  • Triage Stage changed from Unreviewed to Accepted

comment:7 Changed 7 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [9055]) Fixed #8409 -- The runserver now uses conditional GET for admin media files, instead of reloading the files off disk for every request. Thanks for reporting, andylowry

Note: See TracTickets for help on using tickets.
Back to Top