Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 645
Adam Heath Avatar asked Jul 20 '15 17:07

Adam Heath


1 Answers

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.

like image 189
Justin Fagnani Avatar answered Nov 04 '22 12:11

Justin Fagnani