Django

Code

Ticket #8409 (closed: fixed)

Opened 3 months ago

Last modified 3 months ago

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

Reported by: andylowry Assigned to: nobody
Milestone: Component: HTTP handling
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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).

Attachments

Change History

08/19/08 03:55:06 changed by ubernostrum

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to invalid.
  • needs_tests changed.
  • needs_docs changed.

The dev server really isn't built for speed.

08/19/08 06:04:12 changed by anonymous

  • status changed from closed to reopened.
  • has_patch set to 1.
  • resolution deleted.

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]

08/24/08 09:14:49 changed by Piotr Lewandowski <django@icomputing.pl>

  • component changed from Uncategorized to HTTP handling.

09/14/08 05:18:22 changed 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.

09/17/08 00:41:03 changed 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.

09/17/08 00:41:08 changed by adrian

  • stage changed from Unreviewed to Accepted.

09/17/08 00:42:12 changed by adrian

  • status changed from reopened to closed.
  • resolution set to fixed.

(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


Add/Change #8409 (Django built-in server is very slow with Firefox browser when serving admin media)




Change Properties
Action