Skip to content

Instantly share code, notes, and snippets.

@rwehresmann
Created January 4, 2020 01:50
Show Gist options
  • Select an option

  • Save rwehresmann/cd2a5b776cc7e502bc23a274835e3463 to your computer and use it in GitHub Desktop.

Select an option

Save rwehresmann/cd2a5b776cc7e502bc23a274835e3463 to your computer and use it in GitHub Desktop.
We can improve the webpage performance only loading the necessary css first (above the fold), and the rest afterwards. That result in the CSSOM finishing its load faster.
<script type="text/javascript">
const loadStylesheet = src => {
if(document.createStylesheet)
document.createStylesheet(src);
else {
const stylesheet = document.createElement('link');
stylesheet.href = src;
stylesheet.type = 'text/css';
stylesheet.rel = 'stylesheet';
document.getElementsByTagName('head')[0].appendChild(stylesheet);
}
}
window.onload = function() {
loadStylesheet('./style2.css');
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment