Last active
October 19, 2017 15:38
-
-
Save georgebent/642b4c50a78498042f2a300381add2c0 to your computer and use it in GitHub Desktop.
optimizeCSSLoading
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
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); |
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
<!-- include after footer --> | |
<noscript id="deferred-styles"> | |
<link href="{{ asset('css/app.css') }}" rel="stylesheet"> | |
<link href="{{ asset('css/additional.css') }}" rel="stylesheet"> | |
</noscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment