将 javascript-依赖项包装在 HTML-导入中?

Wrap javascript-dependencies in HTML-Import?

为了在 web 组件中使用 javascript-库,我看到了将它们包装成 html-import 的模式,如下所示:

(moment.html)

<script type="application/javascript" src="bower_components/moment/moment.js"></script>

(component.html)

<link rel="import" href="moment.html">

而不是直接在 component.html 中导入脚本。仅使用 html-imports 有什么优势吗?

将它直接嵌入 HTML 有很多好处:它消除了额外的 HTTP 请求(无论请求延迟时间如何,这都会减慢网页的加载速度)。

但是成本是可维护性,这意味着您的 component.html 文件现在直接依赖于原本会被抽象掉的东西(moment.html - 因为 component.html 应该是不知道 moment.html 的依赖项)。