collectstatic command should output minified files

283 views
Skip to first unread message

Diptesh Choudhuri

unread,
Dec 21, 2020, 8:54:35 PM12/21/20
to Django developers (Contributions to Django itself)
The default files copied to STATIC_ROOT when you run python manage.py collectstatic should have two versions- file.js and file.min.js (similarly for css files). As far as I can see, this happens only for the preinstalled apps (like admin/actions.min.js) but not for user installed apps.
Serbing minified static files is important for all production environments for pretty much everyone who uses vanilla django. Though there are packages out there to do this, I feel it is important enough and has enough use cases to be added to the django core.

I can start working on this if it is accepted.
Let me know what you think!

Best
Diptesh Choudhuri

Arvind Nedumaran

unread,
Dec 21, 2020, 9:03:54 PM12/21/20
to Django developers

I kinda like the idea of being able to run collectstatic and not have to worry about setting up a full on frontend workflow for pretty much just minification. It is a great default to have when this is all you need.

That said, I’d be more interested in seeing something like an official or a django-blessed unofficial default option similar to the sprokects-rails gem for ruby. Allowing for a much more flexible and extensive frontend pipeline without having to rely on an external task runner.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/5bcb1522-3486-452e-b061-2cce2bb6d2c9n%40googlegroups.com.

quest...@gmail.com

unread,
Dec 22, 2020, 5:06:01 AM12/22/20
to Django developers (Contributions to Django itself)

Adam Johnson

unread,
Dec 22, 2020, 5:20:07 AM12/22/20
to django-d...@googlegroups.com
django-compressor is also popular: https://pypi.org/project/django-compressor/

IMO we should not include anything in Django since JavaScript is a separate language, and they have much better tools for minification and bundling, and these tools can move faster than and orthogonally to Django. And there are many options: Webpack, Parcel, Gulp, Grunt, Rollup, ..



--
Adam

Dmitriy Sintsov

unread,
Dec 22, 2020, 5:29:53 AM12/22/20
to django-d...@googlegroups.com
There is one trouble: Webpack assumes it's own subtree of assets to process, while Django loads assets from packages (Django apps) directories. I still haven't seen a successful setup of webpack which would respect loading assets from Django packages directories.
Another trouble, not everyone wants to carry node.js subsystem with it's huge list of packages in their Python / Django project.
But there are changes that transpiling would not be required in the future at all, after IE11 would fade to the past:

You received this message because you are subscribed to a topic in the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-developers/dZDRivF29po/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM2xcYM9M1AB-ZK47V4JHH0mNoYvXntz8-wrbzxdOJ1QFg%40mail.gmail.com.

Arvind Nedumaran

unread,
Dec 22, 2020, 6:33:23 AM12/22/20
to django-d...@googlegroups.com
I didn't mean we should include things in Django. Even a workflow that integrates with Django using manage.py commands will be super useful.

Right now, I use Parcel + Tailwind (csspostprocessor mostly) + done JavaScript. It's supposed to be simple.

Even for this, I need to run to terminals (one for Django, one for the frontend) or use something like Honcho with a procfile just so I can develop in peace. Or I should hack gulp to run Django runserver for me.

This is not documented anywhere officially but is a very very common workflow even for small applications.

I'm saying we do something to make this an easier process.


From: django-d...@googlegroups.com <django-d...@googlegroups.com> on behalf of Dmitriy Sintsov <quest...@gmail.com>
Sent: Tuesday, December 22, 2020 3:59:15 PM
To: django-d...@googlegroups.com <django-d...@googlegroups.com>
Subject: Re: collectstatic command should output minified files
 

Diptesh Choudhuri

unread,
Dec 22, 2020, 6:58:38 AM12/22/20
to Django developers (Contributions to Django itself)
Correct. Also having to use third party packages (and even other languages!) for something so common and so useful feels incorrect somehow. 

Additionally, I also propose that  the HTMl files served by wsgi.py are minified. This will be significantly more difficult to achieve since HTML pages are served on the fly. But I think the benefits would surely outweigh the maintenance costs these features bring.

Mariusz Felisiak

unread,
Dec 22, 2020, 7:42:58 AM12/22/20
to Django developers (Contributions to Django itself)
-1

Correct. Also having to use third party packages (and even other languages!) for something so common and so useful feels incorrect somehow. 

Additionally, I also propose that  the HTMl files served by wsgi.py are minified. This will be significantly more difficult to achieve since HTML pages are served on the fly. But I think the benefits would surely outweigh the maintenance costs these features bring.

This idea has already been rejected, see #18524, and I agree with Aymeric's judgement.

About minifying JavaScript files, I don't see a strong reasons to include it in Django, it is a separate language (as pointed out by Adam), well-supported 3rd party apps already exist e.g. django-compressor, and this would require introducing many new dependencies which is always highly controversial.

Best,
Mariusz

Adam Johnson

unread,
Dec 22, 2020, 7:44:11 AM12/22/20
to django-d...@googlegroups.com


Additionally, I also propose that  the HTMl files served by wsgi.py are minified.
 
This can already be done with e.g. https://htmlmin.readthedocs.io/en/latest/reference.html#wsgi-middlware . But normally HTML minification isn't particularly worth it since gzip/brotli can compress it well already.



--
Adam

Adam Johnson

unread,
Dec 22, 2020, 8:34:01 AM12/22/20
to django-d...@googlegroups.com
For those who want more information on getting Django to serve your frontend assets, Aymeric wrote some good react-focussed blog posts: https://fractalideas.com/blog/making-react-and-django-play-well-together-hybrid-app-model/
--
Adam
Reply all
Reply to author
Forward
0 new messages