40

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

Adam Heath
  • 4,703
  • 2
  • 35
  • 50

1 Answers1

7

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.

Justin Fagnani
  • 10,483
  • 2
  • 27
  • 37
  • Could you please be more elaborate? Are you essentially saying that the widget should not rely on Polymer and instead the web page who is loading the extension should be responsible for making Polymer available? – dipole_moment Feb 01 '16 at 16:15
  • No, I'm saying that the element will depend on Polymer via a dependency in it's bower.json, and Bower will warn on incompatible versions of Polymer. All Polymer elements should directly import polymer.html via an HTML import. – Justin Fagnani May 20 '16 at 23:57