#31524 closed Cleanup/optimization (fixed)
Stop minifying only some admin static assets
Reported by: | Jon Dufresne | 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
Here is a list of JavaScript files in the admin app and their size:
20K django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js 15K django/contrib/admin/static/admin/js/inlines.js 13K django/contrib/admin/static/admin/js/SelectFilter2.js 8.8K django/contrib/admin/static/admin/js/urlify.js 7.6K django/contrib/admin/static/admin/js/calendar.js 6.7K django/contrib/admin/static/admin/js/actions.js 5.9K django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js 5.4K django/contrib/admin/static/admin/js/core.js 5.3K django/contrib/admin/static/admin/js/SelectBox.js 5.2K django/contrib/admin/static/admin/js/inlines.min.js 3.2K django/contrib/admin/static/admin/js/actions.min.js 1.9K django/contrib/admin/static/admin/js/collapse.js 1.5K django/contrib/admin/static/admin/js/prepopulate.js 1.1K django/contrib/admin/static/admin/js/autocomplete.js 911 django/contrib/admin/static/admin/js/collapse.min.js 878 django/contrib/admin/static/admin/js/cancel.js 674 django/contrib/admin/static/admin/js/change_form.js 569 django/contrib/admin/static/admin/js/popup_response.js 495 django/contrib/admin/static/admin/js/prepopulate_init.js 379 django/contrib/admin/static/admin/js/prepopulate.min.js 363 django/contrib/admin/static/admin/js/jquery.init.js
Some things to notice:
- Only 4 out of 17 files are minified.
- The largest file, DateTimeShortcuts.js, is only 20 KB.
- The largest file is also not included in the list of minified files.
- All uncompressed files are smaller than the size of the 3 font assets, each ~80 KB.
- All uncompressed files are smaller than the minified jQuery, ~87 KB.
I'm not sure if there is a deliberate or historical reason that only a fraction of the static assets are minified, but it looks like it could be an oversight. The approach is inconsistent.
Minifying is step a contributor must manually do. The documentation for doing so is here:
This is a step that is easy to forget, myself included. Whether or not one remembers to compress static assets will also affect the outcome of tests.
I suggest we drop the minificaiton of admin files altogether. For such small files, it doesn't seem worth it to add a build step and inconsistently at that.
In a typical production scenarios, the static assets will be cached and possibly compressed. Compressing static assets largely removes the size gains of minification. Additionally, there are third party apps to fill the role of static asset optimization.
I think we should continue to distribute the vendored libraries minified, however as they are not manually handled during typical contributions.
Change History (6)
comment:1 by , 5 years ago
Has patch: | set |
---|
comment:2 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Yes, I think this is reasonable. (It's been slowly bubbling up my nag list for a while so... 👍)
comment:3 by , 5 years ago
There are additional problems that occur with minifying along with changes rather than at release/build time:
- It is possible to forget to do it and missing changes are only noticed in production, i.e. with
DEBUG = False
. - Two competing pull requests could minify independently and the one merged second could lose the changes of the first unless rebased and minified correctly.
comment:4 by , 5 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
https://github.com/django/django/pull/12821