Created
February 20, 2014 23:57
-
-
Save brandonpapworth/9125981 to your computer and use it in GitHub Desktop.
meta tag based javascript include definition
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title><!-- whatever -->A Title</title> | |
<meta charset="utf-8"> | |
<!-- [START] script define start --> | |
<meta name="jsinject-modernizer" content="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.min.js"> | |
<meta name="jsinject-jquery" content="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"> | |
<!-- [END] script define --> | |
<!-- [START] js injection code --> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
;(function(){ | |
var sStart = '<'+'scr'+'ipt src="', | |
sEnd = '">'+'<'+'/sc'+'ript'+'>\n', | |
metaTags = document.getElementsByTagName('meta'), | |
finalBlockToWrite = '\n', | |
urlPrefix = window.location.protocol === 'file:' ? 'http:' : '', | |
i = 0, | |
L = metaTags.length; | |
while (i < L) { | |
if (typeof metaTags[i].name === 'string' && metaTags[i].name.indexOf('jsinject') === 0 && typeof metaTags[i].content === 'string') { | |
finalBlockToWrite += sStart + (metaTags[i].content.indexOf('//') === 0 ? urlPrefix : '') + metaTags[i].content + sEnd; | |
} | |
i+=1; | |
} | |
document.write(finalBlockToWrite); | |
})(); | |
//]]> | |
</script> | |
<!-- [END] js injection code --> | |
</head> | |
<body> | |
<!-- web page --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment