Philip Walton 建议制作您的生产 JavaScript 的两个副本。 使用基于 Babel 的构建流程很容易做到这一点。
<!-- Browsers with ES module support load this file. -->
<script type="module" src="main.js"></script>
<!-- Older browsers load this file (and module-supporting -->
<!-- browsers know *not* to load this file). -->
<script nomodule src="main-legacy.js"></script>
他为此创建了一个演示项目,您将看到 50% 的文件大小节省。 我认为,通过直接使用现代 JavaScript 方法,还会有其他速度改进。