Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Created August 26, 2014 07:06
Show Gist options
  • Save sTiLL-iLL/cdfac6c407283147edf4 to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/cdfac6c407283147edf4 to your computer and use it in GitHub Desktop.
basic conditional loading (loads when specified elements are present)
/*
The arguments against this practice will be (1) concatenating into existing JS and CSS to save on the number of requests and (2) flash of content style changes. The first argument needs to be judged on a per-case basis; if the required CSS and JS is small, it should be concatenated to a file used throughout the site or site subsection. The second argument can always be hushed with a bit of transition magic!
*/
$('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);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment