Created
January 29, 2018 09:25
-
-
Save pirkka/1defdc8f132c250efd03a6d158f1f687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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