Skip to content

Instantly share code, notes, and snippets.

@synzhang
Created October 10, 2013 05:59
Show Gist options
  • Select an option

  • Save synzhang/6913712 to your computer and use it in GitHub Desktop.

Select an option

Save synzhang/6913712 to your computer and use it in GitHub Desktop.
Javascript Lazy Loading
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment