Can I add JS libraries into user.js?

Jan 05, 2016

I've been using some additional javascript library files, but I'm doing lots of testing and adding them in each time is taking too long and I would like them to load automatically.

Can I just add them into a function which will load as part of user.js with all the other functions?

Is there a way to do something equivalent to this?

8 Replies
Steve Flowers

Hey Luke - 

Couple of ways to do this. If you're referencing libraries on CDN, here's the way I do this in a Javascript Trigger that runs when the timeline starts (added to user.js on publish). In this example, I added the library files to a Web Object, published to reveal the relative path, and added those paths. If using a CDN, you'd change the add_script parameter to your absolute CDN reference.

function add_script(scriptURL,oID) {
var scriptEl = document.createElement("script");
var head=document.getElementsByTagName('head')[0];
scriptEl.type = "text/javascript";
scriptEl.src = scriptURL;
scriptEl.id=oID;
head.appendChild(scriptEl);}

//only want to add these once!
if(document.getElementById('jquery')==null){
add_script("story_content/WebObjects/5rmVJdSA7hX/jquery-1.11.3.min.js","jquery");
add_script("story_content/WebObjects/5rmVJdSA7hX/taffy-min.js","taffy");

}

This discussion is closed. You can start a new discussion or contact Articulate Support.