【问题标题】:html import polymer compatibilityhtml 导入聚合物兼容性
【发布时间】:2023-03-04 02:13:01
【问题描述】:
我知道 Polymer 在所有地方都使用 html 导入。例如。
<link rel="import" href="bower_components/polymer/polymer.html">
我查看了能否用于 html 导入,它指出它仅适用于 chrome。 http://caniuse.com/#search=html%20imports
这是否意味着使用 html 导入(上面的代码)的任何内置聚合物都无法在其他浏览器上运行 - firefox、safari 等,还是我对 html 导入感到困惑?
【问题讨论】:
标签:
html
cross-browser
polymer
【解决方案2】:
要添加到 a1626 回复,确实并非所有浏览器都支持 HTML 导入。此功能将成为 Web 浏览器的标准,但仍是 a work in progress。
不过,你可以使用a1626提到的polyfill。这将允许您在“所有”(现代)浏览器中使用聚合物组件。为此,您只需在 index.html 页面(以及您导入和使用聚合物组件的任何 html 页面,聚合物组件本身除外)中导入 webcomponents.js 脚本。
就像Polymer project website 中所说的那样,您只需要这样做:
<!-- Polyfill Web Components support for older browsers -->
<script src="components/webcomponentsjs/webcomponents-lite.min.js"></script>
既然你可能会从 bower 得到这个 webcomponentsjs,那么它实际上是这样的:
<!-- Polyfill Web Components support for older browsers -->
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
就是这样,您现在可以在所有现代浏览器中使用聚合物 :)
这个库将允许您使用 html 导入,从而允许您在所有现代浏览器中使用聚合物组件。它不会像已经对此提供本机支持的 Chrome 那样快,但仍将完全可用。