Skip to content

Instantly share code, notes, and snippets.

@alisonmonteiro
Created May 18, 2018 18:28
Show Gist options
  • Select an option

  • Save alisonmonteiro/4049fb619197129fe1de3522bbfb15e9 to your computer and use it in GitHub Desktop.

Select an option

Save alisonmonteiro/4049fb619197129fe1de3522bbfb15e9 to your computer and use it in GitHub Desktop.
defered styles
<noscript id="deferred-styles">
<link rel="stylesheet" href="style.css"/>
</noscript>
<script>
function loadDeferredStyles() {
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 = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
if (raf) {
raf(function() {
window.setTimeout(loadDeferredStyles, 0);
});
} else {
window.addEventListener('load', loadDeferredStyles);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment