Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

web component - How to safely load Polymer in unknown environment - multiple versions or namespace?

I have elements built with Polymer which needs to run on multiple sites (a widget) which:

  • Don't have Polymer included (fine, I can include)
  • Polymer already included at a compatible version (brilliant, unlikely)
  • Polymer at an unknown version (too old or too new, tricky)

Is it possible to load Polymer in a namespace? e.g. myObj.Polymer or MyPolymerName

I have found polymer-js which will let me load Polymer as a module, but this isn't an official way. This still exports to the global scope

question from:https://stackoverflow.com/questions/31523106/how-to-safely-load-polymer-in-unknown-environment-multiple-versions-or-namespa

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution for now is to rely on package management to resolve Polymer to a single compatible version for a project and its dependencies, and HTML Imports to de-duplicate loading of dependencies from multiple sources.

If you vend your elements as Bower packages, then a site can include them, with their dependencies and imports of Polymer, and if a compatible version of Polymer is available, use that one version across the whole project.

In the future version of Polymer, after ES6 modules and loaders are fully spec'ed, we will probably have a version of Polymer that's only exported via modules so that multiple versions can be scoped to their explicit imports and can safely coexist on a page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...