Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: simplify troubleshooting of incorect mime types for .js static files #2046

Open
blep opened this issue Dec 28, 2024 · 3 comments

Comments

@blep
Copy link

blep commented Dec 28, 2024

The troubleshooting documentation makes it difficult for new Django developers like me who follow the Django tutorial and run into an issue:
https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#troubleshooting

  • First, it should tell you to check the console window for message about incorrect MIME type when loading toolbar.js (was text/plain for me, running on Windows O.S.). For me the error message was (sorry, in French):
    Le chargement du module à l’adresse « http://localhost:8000/static/debug_toolbar/js/toolbar.js » a été bloqué en raison d’un type MIME interdit (« text/plain »).
  • Second, the workarounds are complexe, involve global system configuration changes, are missing detailed steps and need to be performed on each developer's machine.

A much simpler work-around is to add the following to your settings.py, which forces the MIME type of .js files:

import mimetypes
mimetypes.add_type("application/javascript", ".js", True)

This resolved the issue for me without system-wide change.
May even want to add these steps as part of the installation instruction, to ensure it runs on any system.

@matthiask
Copy link
Member

Thanks for your report! It does sound like a recurring frustrating experience for newcomers.
We have discussed this previously in #1336 and have decided to not add the workaround to the toolbar, and instead ask the Django devs to do something about it. I still think this would be the better way since this affects all development environments on Windows with broken mimetypes, and magically fixing it by installing the toolbar sounds totally non-obvious to me. That being said, we are in position to do something about it even if it's not really out issue, and we could point users to the workaround too, maybe with the necessary warnings.

@tim-schilling
Copy link
Member

Agreed that we should include the error message we're expecting to see. @blep would you be interested in creating a PR to include that information in the docs?

On the problem in general, I wonder if we could write some JS to detect when the file fails to load to present better information to the user. Perhaps we load it into the toolbar info panel in #2033 or the static files panel?

@blep
Copy link
Author

blep commented Dec 28, 2024

@tim-schilling I'll look into making a PR for the documentation to indicate that users should check the console for messages and to suggest the simpler workaround I provided.

If I followed the chain correctly, #1336 forwards to Django ticket #32041 which forwards to python/cpython#54760, which has been closed. So as far as I understand, there is no pending action to fix the root cause of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants