Add an option to resolve static paths in javascript #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The ManifestStaticFilesStorage will replace import/export statements in javascript, and url() statements in css. But if for example you do dom manipulations in javascript and want to reference a static file you have to roll your own sollution to reference the correct static file. Typically you will call the static command in a template and pass it to javascript as a data attribute or in a script of type=application/json, see this classic stack overflow example
This is a proposal to add a generic
django.static
function to the javascript namespace, by using the template tag{% include_staticjs %}
. This then allows you to usedjango.static("image.png")
in your javascript and it will return the correct path eg,"/static/image.123xyz.png"
This makes it more convenient to use static files in javascript when doing dom manipulations, etc.
It would probably be possible that collectstatic changes the javascript files, instead of using a javascript funciton, but this wouldn't work for development and it seems better to keep them working the same way.