Last active
December 16, 2015 12:39
-
-
Save eunomie/5436312 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
/** | |
* The default implementation of the import function. Writes a script tag to | |
* import the script. | |
* | |
* @param {string} src The script source. | |
* @return {boolean} True if the script was imported, false otherwise. | |
* @private | |
*/ | |
goog.writeScriptTag_ = function(src) { | |
if (goog.inHtmlDocument_()) { | |
var doc = goog.global.document; | |
if (doc.readyState == 'complete') { | |
var isDeps = /\bdeps.js$/.test(src); | |
if (isDeps) { | |
return false; | |
} else { | |
throw Error('Cannot write "' + src + '" after document load'); | |
} | |
} | |
doc.write( | |
'<script type="text/javascript" src="' + src + '"></' + 'script>'); | |
return true; | |
} else { | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exemple tout bête dont j'ai enlevé les commentaires. Et pourtant, petite fonction de 20 lignes, assez simples.
Pourquoi les tests sur readyState et sur isDeps ?
Contexte : chargement de script dans une lib js. inHtmlDocument permet de savoir si on est dans une page html ou non (node par exemple). goog.global.document va contenir en gros window.document.