Opened 6 years ago

Closed 6 years ago

#30229 closed Cleanup/optimization (fixed)

inlines.min.js contains an unnecessary polyfill

Reported by: djw Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Due to the use of .find() in this code, the Closure Compiler is adding a polyfill. However, find is only being called on jQuery objects, so this is unnecessary, and adds around 1kb to the minified file.

Change History (3)

comment:1 by djw, 6 years ago

Has patch: set

comment:2 by Tim Graham, 6 years ago

Triage Stage: UnreviewedReady for checkin

Dan's explanation of why adding rewrite_polyfills=false to compress.py is okay:

The parameter's badly-named, but it controls whether polyfills are added to the code when the compiler detects that ES6+ features are being used.

In this case, it thinks Array.prototype.find is being used, which is an ES2015 feature, and isn't available in all browsers. The polyfill code will add an implementation for browsers which don't have a native implementation.

Django's inlines.js only uses jQuery's .find() method, so this polyfill is unnecessary.

It's possible that in future we'd want to rewrite Django's JavaScript code using more modern syntax, which might require the use of polyfills. However, I in that case I think it would be preferable to add those libraries explicitly, rather than have them added during minification.

comment:3 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: newclosed

In fe65918:

Fixed #30229 -- Removed polyfill from inlines.min.js.

find() is only called on jQuery objects, so the polyfill is necessary.

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