ManifestStaticFilesStorage, reference static files from each other

I am using:
This allows me to use long cache times, and resources are never stale.

However in my Javascript files, I need to reference a CSS file, however due to the changing hash extension in its filename, I don’t know how to reference the name of the file within JavaScript.

Does anyone have an idea how this could be achieved?

Emit the value in your template within a json_script tag, and have your JavaScript read the value from that entry.

1 Like

Ken’s approach will work fine. For "why use json_script" see this post.

A second approach, if you’re doing this for many CSS files, is to add a regex to a subclass of ManifestStaticFilesStorage to have it update references in your JS files. I did this recently in this Django ticket for JS sourcemaps, which can serve as reference.