Rejuvenating vs deprecating Form.Media

Hi! I’m catching up on this conversation. Can I point you to the thread I opened about integrating importmaps and the project I started to implement this idea?

The main idea behind dj-importmap is to declare importmaps in a Django project in a way that IDEs can comprehend to propose autocolpletion in JS files if that becomes the Django standard. dj-importmap relies on a importmaps.py similar to how urls.py works (from a user perspective). I started to use it on a project for a client and I’d love to see the community get behind it, expand it with features and adopt it (or another) as the standard.

Also, related to this, I’d really love a mechanism for templates to declare assets so the view can collect them and include them only once, quite similar to what Media proposes for Form. It is not rare to me to get in the situation where I’d like to {% include %} a partial — potentially more than once — in a template but that partial requires some JS code to be useful. In that situation, the only solution I have is to leave a comment on the template to indicate that these assets also need to be included in the template, which is not conform to the modern practice of declaring self-sufficient components.

I don’t know how complex it is to develop, but I imagine an {% asset %} tag that would do for templates what Media does for form. That tag would be treated differently to other tag and processed at the very end of rendering so that all assets declared by all partials are collected and made available for inclusion in the HTML.

1 Like