Skip to content

Instantly share code, notes, and snippets.

@WunGCQ
Created February 27, 2017 16:16
Show Gist options
  • Save WunGCQ/ceee119f22452970db0ec2c3d90fab65 to your computer and use it in GitHub Desktop.
Save WunGCQ/ceee119f22452970db0ec2c3d90fab65 to your computer and use it in GitHub Desktop.
javascript check css in html document loaded
function check(){
setTimeout(()=>(
var len = 0, arr = [],count = 0;
arr = Array.prototype.slice.call(document.head.children).filter(el=>((el.tagName == 'LINK'&& el.href) || (el.tagName == 'SCRIPT' && el.src))),len = arr.length,arr).forEach(e=>
e.addEventListener('load',()=>console.log(`finished ${++count} of ${len}`))),0);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
setTimeout(()=>(window.len = 0, arr = [],count = 0,arr = Array.prototype.slice.call(document.head.children).filter(el=>((el.tagName == 'LINK'&& el.href) || (el.tagName == 'SCRIPT' && el.src))),len = arr.length,arr).forEach(e=>
e.addEventListener('load',()=>console.log(`finished ${++count} of ${len}`))),0);
</script>
<link rel="stylesheet" href="./test1.css">
<link rel="stylesheet" href="./test2.css">
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment