Add deferred CSS loading
This commit is contained in:
parent
a3f29235f6
commit
ecf36b469f
1 changed files with 16 additions and 0 deletions
|
@ -8,5 +8,21 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<a href="#top">Top</a>
|
<a href="#top">Top</a>
|
||||||
</div>
|
</div>
|
||||||
|
<noscript id="deferred-styles">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{{ .Site.BaseURL }}/css/main.css"/>
|
||||||
|
</noscript>
|
||||||
|
<script>
|
||||||
|
var loadDeferredStyles = function() {
|
||||||
|
var addStylesNode = document.getElementById("deferred-styles");
|
||||||
|
var replacement = document.createElement("div");
|
||||||
|
replacement.innerHTML = addStylesNode.textContent;
|
||||||
|
document.body.appendChild(replacement);
|
||||||
|
addStylesNode.parentElement.removeChild(addStylesNode);
|
||||||
|
};
|
||||||
|
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
|
||||||
|
webkitRequestAnimationFrame || msRequestAnimationFrame;
|
||||||
|
if (raf) raf(function() { window.setTimeout(loadDeferredStyles, 0); });
|
||||||
|
else window.addEventListener('load', loadDeferredStyles);
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue