How do you wait for a CDN script take to load before executing?

Hi,

I am trying to use Optimizely.com which requires a CDN based script. I have including the script tag within a <head> tag.

I am then activating it in my Template.<some template>.onRendered , however it seems like the object defined in the CDN script is not ready when the page renders.

Is there a best practices approach to dealing with this?

any help appreciated

instead of including the script in the head you can use jquery to load it in the onRendered

$.getScript(url,function(){
   //code to execute after script has been loaded
});

@jj227 thanks… was just about to try that exact option. I just was not sure if this is best practices… I did see some other approaches like https://atmospherejs.com/manuelschoebel/wait-on-lib