Skip to content

Instantly share code, notes, and snippets.

@curiositry
Created May 25, 2014 01:06
Show Gist options
  • Select an option

  • Save curiositry/90e377d1b91c402ce536 to your computer and use it in GitHub Desktop.

Select an option

Save curiositry/90e377d1b91c402ce536 to your computer and use it in GitHub Desktop.
Defer loading CSS via google PageSpeed
<html>
<head>
<style>
.blue{color:blue;}
</style>
</head>
<body>
<div class="blue">
Hello, world!
</div>
<script>
var cb = function() {
var l = document.createElement('link'); l.rel = 'stylesheet';
l.href = 'small.css';
var h = document.getElementsByTagName('head')[0]; h.parentNode.insertBefore(l, h);
};
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) raf(cb);
else window.addEventListener('load', cb);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment