简体   繁体   中英

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.)

Thanks in advanced for anyone with the expertise to assist me.

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({});
});

For anyone needing help with this, replace Meteor.startup with Template.name.onRendered. This helped solve my issue. Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM