Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created June 6, 2014 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/762eb5c9cd3313b6fde9 to your computer and use it in GitHub Desktop.
Save steveosoule/762eb5c9cd3313b6fde9 to your computer and use it in GitHub Desktop.
Lazy Load JavaScript
<!-- FROM: http://googlecode.blogspot.com/2009/09/gmail-for-mobile-html5-series-reducing.html -->
<html>
...
<script id="lazy">
// Make sure you strip out (or replace) comment blocks in your JavaScript first.
/*
JavaScript of lazy module
*/
</script>
<script>
function lazyLoad() {
var lazyElement = document.getElementById('lazy');
var lazyElementBody = lazyElement.innerHTML;
var jsCode = stripOutCommentBlock(lazyElementBody);
eval(jsCode);
}
</script>
<div onclick=lazyLoad()> Lazy Load </div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment