Created
October 2, 2015 07:27
-
-
Save noisan/f3b9738c02fc62fe5a08 to your computer and use it in GitHub Desktop.
Async CSS loader snippet inspired by https://github.com/filamentgroup/loadCSS/
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>loadCSS test</title> | |
<script> | |
(function(w, href) { | |
"use strict"; | |
var d = w.document; | |
var ss = d.createElement('link'); | |
ss.rel = "stylesheet"; | |
ss.href = href; | |
ss.media = "only x"; | |
/* ignore window.document.styleSheets, use link.onload() again */ | |
ss.onload = function() { | |
ss.onload = function() {}; | |
ss.media = "all"; | |
}; | |
/* use window.onload(), too... */ | |
if (w.addEventListener) { | |
w.addEventListener('load', ss.onload); | |
} else if (w.attachEvent) { | |
w.attachEvent("onload", ss.onload); | |
} else { | |
var c = w.onload; | |
var b = ss.onload; | |
w.onload = function() { b.call(this); c&&c.call(this); }; | |
} | |
var refs = (d.body || d.getElementsByTagName("head")[0]).childNodes; | |
var ref = refs[refs.length - 1]; | |
ref.parentNode.insertBefore(ss, ref.nextSibling); | |
return ss; | |
}(this, './css.php?t=3')); | |
</script> | |
</head> | |
<body> | |
<p>This is a test page.</p> | |
<p id="test">test:</p> | |
</body> | |
</html> |
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
<?php | |
header('content-type: text/css'); | |
if (isset($_REQUEST['t'])) { | |
sleep($_REQUEST['t']); | |
} | |
?> | |
#test { background-color: greenyellow; } | |
#test::after{ content: "(OK!)"; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment