Add deferred CSS loading

This commit is contained in:
Tony Blyler 2016-11-03 15:04:28 -04:00
parent a3f29235f6
commit ecf36b469f

View file

@ -8,5 +8,21 @@
{{ end }}
<a href="#top">Top</a>
</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>
</html>