Polymer dist /文件夹有一个HTML文件https://github.com/Polymer/polymer/tree/master/dist,带有HTML导入和脚本标记 . 大多数聚合物元素都不是提供像polymer.js这样的单一分布束文件并对那里可用的每种聚合物元素做同样的事情的良好做法吗?
这种方法有一些明显的优点:
1. Minimum http requests to get the polymer core or a polymer element.
2. Easy to use for the clients, just include the required element.
示例:依赖于其他共享元素的元素,
- shared-element: /webcomponents/font-roboto/roboto.js
- custom-element1: uses shared-element
- custom-element2: uses shared-element
使用custom-element1和custom-element2的应用程序仅使用一个http请求下载/webcomponents/font-roboto/roboto.js一次 .
<script src="../webcomponents/webcomponentsjs/webcomponents.js"></script>
<script src="../webcomponents/custom-element1/custom-element1.js"></script>
<script src="../webcomponents/custom-element2/custom-element2.js"></script>
PS:上面的custom-element1.js与custom-element1.html做同样的事情,期望以编程方式加载和访问组件很方便 .
我想听听聚合物团队或其他聚合物开发商/用户关于解决这个问题的最佳实践 .
1 回答
如果我正确理解你,你想要的就是硫化 . 截至本文撰写时,对于聚合物1.0,说明如下:
https://www.polymer-project.org/1.0/tools/optimize-for-production.html