Load JS library before main template DOM insertion

I am trying to get the webcomponents polyfill working but either a Meteor update or a Polymer/Polyfill update made it so that it doesn’t work properly anymore. I’ve deployed a super basic app which you can find below. You can also look at the thread where I’m asking for help.

https://groups.google.com/forum/#!topic/polymer-dev/bB-IMYvHJyw
http://webcomponents.meteor.com/

Apparently the issue comes from the polyfill being loaded after the custom DOM elements (such as paper-button) are inserted. Indeed, that’s the case, so I thought ok let’s move the js polyfill from public into client and into a lib folder to make it load asap. However, the polyfill still only loads after the whole

!function(){Template.body.addContent(function(){

DOM insertion into the template. What can I do in this case? Any ideas how to solve this issue?

After looking at the Meteor JS code it would appear that the only way to load the webcomponents polyfill before any DOM insertion would be to import the polyfill through a package if I’m not mistaken?

1 Like

Seems like this could work!

Does putting things I the “compatibility” folder not do the trick? I’ve not had to do so myself, but from what I understand it loads all the things first…but maybe not before the DOM is rendered though…

Thanks, didn’t know about that folder! Will look into it :slight_smile: .Hmm nope doesn’t seem to do the trick. I think this executes too early LOL. There’s no window object yet when compatibility gets executed, therefore the polyfill relying on the window object crashes the server.

I think compatibility is really just for defining variables?

Yeah, it looks to be for legacy libs that require var to be global in scope :frowning: look close at meteor source for undocumented (_thing) hooks…likely there is something that will get you where you need to be in the rendering pipeline

Did you find a solution to the problem ?

per the docs, files starting with main are loaded last, perhaps this would be the best place to try to solve the problem?