Created
August 14, 2020 17:35
-
-
Save poltorrr/cdda7ad1c249577eec4b80aa5ba6a096 to your computer and use it in GitHub Desktop.
load script
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
| <script> | |
| function loadScript(url, callback) { | |
| let selector = 'script[src*="' + url + '"]'; | |
| if (!document.querySelector(selector)) { | |
| let script = document.createElement("script"); | |
| script.type = 'text/javascript'; | |
| if (script.readyState) { //IE | |
| script.onreadystatechange = function () { | |
| if (script.readyState === 'loaded' || | |
| script.readyState === 'complete') { | |
| script.onreadystatechange = null; | |
| if (callback) { | |
| callback(); | |
| } | |
| } | |
| }; | |
| } else { //Others | |
| script.onload = function () { | |
| if (callback) { | |
| callback(); | |
| } | |
| }; | |
| } | |
| script.src = url; | |
| document.body.appendChild(script); | |
| } | |
| } | |
| loadScript('js/vendor/jquery-3.5.1.min.js', () => { | |
| consol.log('loaded') | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment