Created
March 27, 2014 05:45
-
-
Save chirag64/9801111 to your computer and use it in GitHub Desktop.
Lazy Load JS & CSS files example
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
//Lazy load example | |
//Load CSS and JS files only if the pre tag elements are present within the article tag | |
$('article pre').length && (function() { | |
var mediaPath = '/assets/'; | |
$('<link>').attr({ | |
type: 'text/css', | |
rel: 'stylesheet', | |
href: mediaPath + 'css/syntax.css' | |
}).appendTo(document.head); | |
var syntaxScript = document.createElement('script'); | |
syntaxScript.async = 'true'; | |
syntaxScript.src = mediaPath + 'js/syntax.js'; | |
doc.body.appendChild(syntaxScript); | |
})(); | |
//Referenced from http://davidwalsh.name/lazy-load-elements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment