Skip to content

Conversation

blighj
Copy link
Owner

@blighj blighj commented Jul 27, 2025

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 use django.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.

@blighj
Copy link
Owner Author

blighj commented Jul 27, 2025

I guess this is similar to RAILS_ASSET_URL as mentioned on this discussion django/new-features#11, but that is not an actual JS function, it is a compiler directive rails/propshaft#207

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

Successfully merging this pull request may close these issues.

1 participant