Skip to content

Instantly share code, notes, and snippets.

@dbushell
Created March 23, 2015 11:38
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 dbushell/beb25b8352ed896d85d4 to your computer and use it in GitHub Desktop.
Save dbushell/beb25b8352ed896d85d4 to your computer and use it in GitHub Desktop.
Poll Stylesheets until they exist in document.styleSheets
var stylesheets = Array.prototype.slice.call(document.querySelectorAll('link[href*=".css"]'))
var sheets = document.styleSheets;
function pollSheets() {
var i, j, load_count = 0;
for (i = 0; i < stylesheets.length; i++) {
for (j = 0; j < sheets.length; j++) {
// check if stylesheet exists in document.styleSheets
if (sheets[j].href && sheets[j].href.indexOf( stylesheets[i].href ) > -1) {
console.log('ready: ' + stylesheets[i].href);
load_count++;
}
}
}
if (load_count >= stylesheets.length) {
// done
console.log('all ready');
return;
}
// poll again
setTimeout(pollSheets);
}
pollSheets();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment