Created
July 6, 2018 09:33
-
-
Save ajayvarghese/293ec1efe94d5b8ccd1e1bcf54f472d5 to your computer and use it in GitHub Desktop.
Load CSS file after page load, which is not required for the initial view of the page.
This file contains hidden or 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
const loadStyleSheet = src => { | |
if(document.createStylesheet) { | |
document.createStylesheet(src); | |
} else { | |
const stylesheet = document.createElement('link'); | |
stylesheet.href = src; | |
stylesheet.rel = 'text/css'; | |
document.querySelector('head').appendChild(stylesheet); | |
} | |
} | |
window.onload = function() { | |
console.log('Loaded'); | |
const path = 'CSS FILE PATH WHICH SHOULD BE LOADED LATER'; | |
loadStyleSheet(path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment