Created
August 14, 2017 17:41
-
-
Save micalexander/cac27b422bcf15cb134cb5c361e77295 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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