Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(function(url) {
console.log('is jQuery.timeago defined?');
console.log((typeof(jQuery.timeago) !== 'undefined'));
var tag = 'script';
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if(request.readyState === 4) {
console.log('we have fetched the script');
if(request.status === 200) {
var javascript = request.responseText;
console.log('the javascript looks something like this: ' + javascript.substr(0,50));
eval(javascript);
console.log('evaluated the javascript');
var scriptTag = document.createElement(tag);
scriptTag.innerHTML = javascript;
document.getElementsByTagName('head')[0].appendChild(scriptTag);
console.log('is jQuery defined?');
console.log((typeof(jQuery) !== 'undefined'));
console.log('is jQuery.timeago defined?');
console.log((typeof(jQuery.timeago) !== 'undefined'));
console.log('is $.timeago defined?');
console.log((typeof($.timeago) !== 'undefined'));
} else {
console.log('error while loading the script :(');
}
}
}
request.open("GET", url);
request.send();
return null;
}("https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.min.js"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment