今天在生产环境中部署 ES2015+ 代码

Avatar of Chris Coyier
Chris Coyier

DigitalOcean 为您旅程的每个阶段提供云产品。 立即开始使用 200 美元的免费额度!

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 方法,还会有其他速度改进。

直接链接 →