cookiecutter / cookiecutter-django

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.
https://cookiecutter-django.readthedocs.io
BSD 3-Clause "New" or "Revised" License
12.09k stars 2.89k forks source link

Use Django Browser Reload instead a Javascript based one for auto reload #3745

Open Benoss opened 2 years ago

Benoss commented 2 years ago

Description

For a long time I used gulp and JS based BrowserReload to auto reload when a change is made in CSS/JS. Recently I converted my projects to use https://github.com/adamchainz/django-browser-reload

Rationale

Andrew-Chen-Wang commented 2 years ago

this is really cool! Not sure if it would be too dev opinionated, but I +1 it

browniebroke commented 2 years ago

Nice suggestion, the rationale makes a lot of sense. I would be interested to see what such change would look like, especially with the Docker setup.

Benoss commented 2 years ago

Not sure what are the current issues with the Docker setup (I am using a local setup) but django-browser-reload should just work. It is using django.http.StreamingHttpResponse under the hood to push state back to the browser and reload the tab this means that's the same webserver than the one serving your we pages. If you can see a page then you should be able to reload it. The install is not more difficult than Django debug toolbar. I haven't tested with Django Compressor but it should also work out of the box.

browniebroke commented 2 years ago

Not sure what are the current issues with the Docker setup

It's not so much of any specific issues. In my experience, these types of auto-reload sometimes rely on some extra connections that can be blocked from within the container. May or may not be an issue here, just something to watch out for I guess.

I'm open to review a pull request with such change, would you like to work on this? If you can port what you did so far, we can then assess whether Docker is actually a problem or not.

Benoss commented 2 years ago

@browniebroke I have created a pull request, did a bit of manual testing and it is CI valid. There is no way to auto test this, would be keen for people to test what they usually do when they start a project and check if the reload is working