Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Created April 10, 2021 17:11
Show Gist options
  • Save ihorduchenko/741e527def5e2d953b52624838a90aa5 to your computer and use it in GitHub Desktop.
Save ihorduchenko/741e527def5e2d953b52624838a90aa5 to your computer and use it in GitHub Desktop.
Critical CSS for deferred styles while page is loading
<style id="critical-css">
/* Your styles here */
</style>
<script>
const criticalStyleTag = document.getElementById('critical-css');
document.addEventListener('DOMContentLoaded', function() {
setTimeout(function(){
criticalStyleTag.parentNode.removeChild(criticalStyleTag);
}, 2000);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment