Search code examples
javascriptpolymer-1.0vulcanize

Vulcanize produces repeated scripts


I have created two Polymer custom elements. Both of them uses moment.js. So I have referenced it in both the elements, like: <script src="../../bower_components/moment/min/moment.min.js"></script> I use vulcanize to produce a single import file element.html. The issue is that the content of moment.js appears twice in the vulcanized file. Is this correct? Is there a way to avoid it?


Solution

  • You can create a moment-import.html in which you include the script, and then import that file in both your elements.

    HTML imports are only loaded once across all elements and vulcanize will de-duplicate them for you.