Skip to content

Commit 0c62631

Browse files
jowlojonas-wloka-bruker
authored andcommitted
Load asset files with ending ".mjs" as modules
When script files in the `assets` folder Aare loaded and the file ends in ".mjs", the `type="module"` attribute is added to the `<script>` tag. fix #1904
1 parent 91b6acf commit 0c62631

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
3030
## Changed
3131
- [#2652](https://github.com/plotly/dash/pull/2652) dcc.Clipboard supports htm_content and triggers a copy to clipboard when n_clicks are changed
3232
- [#2721](https://github.com/plotly/dash/pull/2721) Remove ansi2html, fixes [#2613](https://github.com/plotly/dash/issues/2713)
33+
- [#2730](https://github.com/plotly/dash/pull/2721) Load script files with `.mjs` ending as js modules
3334

3435
## [2.14.2] - 2023-11-27
3536

dash/dash.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,20 @@ def _relative_url_path(relative_package_path="", namespace=""):
855855
raise Exception("Serving files from absolute_path isn't supported yet")
856856
elif "asset_path" in resource:
857857
static_url = self.get_asset_url(resource["asset_path"])
858-
# Add a cache-busting query param
859-
static_url += f"?m={resource['ts']}"
860-
srcs.append(static_url)
858+
# Import .mjs files with type=module script tag
859+
if static_url.endswith(".mjs"):
860+
srcs.append(
861+
{
862+
"src": static_url
863+
+ f"?m={resource['ts']}", # Add a cache-busting query param
864+
"type": "module",
865+
}
866+
)
867+
else:
868+
srcs.append(
869+
static_url + f"?m={resource['ts']}"
870+
) # Add a cache-busting query param
871+
861872
return srcs
862873

863874
def _generate_css_dist_html(self):

0 commit comments

Comments
 (0)