Skip to content

Instantly share code, notes, and snippets.

@brandonpapworth
Created February 20, 2014 23:57
Show Gist options
  • Save brandonpapworth/9125981 to your computer and use it in GitHub Desktop.
Save brandonpapworth/9125981 to your computer and use it in GitHub Desktop.
meta tag based javascript include definition
<!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