javascript - Firefox 不会加载类型为 "module"的脚本标签

标签 javascript html firefox ecmascript-6

我正在尝试使用本地服务器在 Firefox 中运行 ES6 JavaScript。因此,我需要使用 "module" 类型的脚本标记,而不是 "text/javascript"。以下内容适用于 Chrome,但不适用于 Firefox。帮忙?

index.html

<!DOCTYPE html>
<html>
<head>
<script type="module" src="main.js"></script>
</head>
<body>
</body>
</html>

main.js

console.log("Hello World");

最佳答案

我们今天刚刚遇到这个问题,因为我们仍然使用 Firefox ESR 52 并且尚未迁移到 ESR 60。

在 Firefox 60 中,此功能默认启用。 Check out the Firefox 60 release notes .

在版本 54 至 59 中,您可以通过 about:config 并设置 dom.moduleScripts.enabled 启用它。 Noted in the script element docs (implementation notes drop down) .

支持 ES6 模块的浏览器将忽略带有 nomodule 的脚本。所以你可以有一个没有模块的脚本作为后备。就像这样:

    <!-- in case ES6 modules are supported -->
    <script type="module" src="main.js"></script>
    <!-- in case ES6 modules aren't supported -->
    <script src="main-fallback.js" defer nomodule></script>

资源

以上建议引自herehere .

这是来自 Jake Archibald 的另一个资源.

关于javascript - Firefox 不会加载类型为 "module"的脚本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49470842/

相关文章:

javascript - 诺基亚 HERE 3.0 中的测地线多边形?

javascript - 为什么我的选择器字段没有直观地更新选项?

linux - 使用 linux 命令行禁用 firefox 中的自动更新

html - 设置表格列宽小于内容

javascript - 下一个按钮用js选择下拉菜单的下一个选项

javascript - 如何从 XUL 向嵌入式 WebExtension 发送消息

css - 外部 CSS 字体仅在 Chrome 中显示(没有 IE 和 Firefox)

javascript - Highcharts - 使用函数更改工具提示

javascript - 使用 Javascript 禁用某些下拉输入字段时出现问题

javascript - 在 IE11 中下载文件出现错误 "' Uint8Array' is undefined”