Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2449 closed defect (fixed)

[patch] GZipMiddleware shouldn't gzip JavaScript

Reported by: ubernostrum Owned by: adrian
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Internet Explorer is known to have issues with gzipped JavaScript content, and in some testing of various AJAXy things I also found some weird issues with JSON responses being mangled only when GZipMiddleware was enabled.

So it'd probably be a good idea for the middleware to look at the outgoing Content-Type and not compress if it's JavaScript.

Attachments (2)

gzip.diff (532 bytes) - added by ubernostrum 9 years ago.
Patch to make GZipMiddleware smarter about JavaScript
gzip.2.diff (533 bytes) - added by ubernostrum 9 years ago.
Better patch using Simon's suggestion

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by ubernostrum

Patch to make GZipMiddleware smarter about JavaScript

comment:1 Changed 9 years ago by ubernostrum

  • Summary changed from GZipMiddleware shouldn't gzip JavaScript to [patch] GZipMiddleware shouldn't gzip JavaScript

comment:2 Changed 9 years ago by Simon Willison

It looks like this patch won't handle the case where the Content-Type header includes a charset:

Content-Type: text/javascript; charset=utf-8

There are routines in the Python email package that can handle parsing this kind of information out of a header, although to be honest the following would probably work fine:

'javascript' in response.headers['Content-Type']

comment:3 Changed 9 years ago by ubernostrum

Ack. Yeah.

Shouldn't submit patches at 4AM...

Changed 9 years ago by ubernostrum

Better patch using Simon's suggestion

comment:4 Changed 9 years ago by jacob

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

(In [3503]) Fixed #2449 -- gzip middleware no longer gzips Javascript. Thanks for the prob, ubernostrum

comment:5 Changed 9 years ago by jacob

Thanks for the *prod*, that is.

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