Skip to content

Instantly share code, notes, and snippets.

@micalexander
Created August 14, 2017 17:41
Show Gist options
  • Select an option

  • Save micalexander/cac27b422bcf15cb134cb5c361e77295 to your computer and use it in GitHub Desktop.

Select an option

Save micalexander/cac27b422bcf15cb134cb5c361e77295 to your computer and use it in GitHub Desktop.
var url = "https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.min.js";
function require( url ) {
var ajax = new XMLHttpRequest();
ajax.open( 'GET', url, false ); // <-- the 'false' makes it synchronous
ajax.onreadystatechange = function () {
var script = ajax.response || ajax.responseText;
if (ajax.readyState === 4) {
switch( ajax.status) {
case 200:
eval.apply( window, [script] );
console.log("script loaded: ", url);
break;
default:
console.log("ERROR: script not loaded: ", url);
}
}
};
ajax.send(null);
}
require(url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment