Search code examples
javascriptmeteor

Loading external JS / JQuery script via MeteorJS


I'm trying to load an external script while using Meteor.

Currently using this code in my layout.js to some success.

Meteor.startup( function() {
    $.getScript('js/scripts.js');
});

However, if I go to another url and come back to it, the script no longer works. (I see it not working because my background cover image disappears.)


Solution

  • Any external scripts should be placed in client/compatibility, and Meteor will load it for you; no need for $.getScript('js/scripts.js');

    You can then instantiate that script on the template like:

    Template.game.onRendered(function(){
      $('.grid').isotope({});
    });