Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33336 closed New feature (duplicate)

Widget.Media.JS ESM support

Reported by: James Pic Owned by: nobody
Component: Forms Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Change History (4)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: duplicate
Status: newclosed

As far as I'm aware we can close is as a duplicate of more general ticket #9357.

comment:2 by James Pic, 3 years ago

And that's how the decision has been made to not support ESM in Django. There goes a very convenient feature for modern web development!

in reply to:  2 comment:3 by Mariusz Felisiak, 3 years ago

Replying to James Pic:

And that's how the decision has been made to not support ESM in Django. There goes a very convenient feature for modern web development!

I wouldn't say that. There are other media types that we could support but the first step to opening this door is to handle Media subclasses in Django. It would be straightforward to support JavaScript modules (or others) with #9357, e.g.:

class MyMedia(Media):
    def __init__(self, media=None, css=None, js=None, js_modules=None):
        self.js_modules = js_modules
        super().__init__(media, css, js)

    def render_js_modules(self):
        return format_html(...)

You can start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think. We can always reopen this ticket after reaching a consensus that JavaScript modules should be treated and handled separately.

comment:4 by James Pic, 3 years ago

Thank you Mariusz! I'm not on the mailing list but if anyone's looking for an example they can use there's one here I just made up: https://yourlabs.io/oss/djhacker/-/commit/0861a15f9d4a57f9841a3e07688e0832fde8d9fc

It also allows for async, defer, etc all script attributes: https://developer.mozilla.org/fr/docs/Web/HTML/Element/script

Version 2, edited 3 years ago by James Pic (previous) (next) (diff)
Note: See TracTickets for help on using tickets.
Back to Top