Created
March 18, 2020 14:10
-
-
Save diegosomar/d1b86a77a9a99dd6ca6527072c8df946 to your computer and use it in GitHub Desktop.
Enable Firefox compatibility to link[rel="preload"]
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
/** | |
* Firefox has no support to link[rel="preload"] | |
* This is a workaround to async load non-critical CSS | |
*/ | |
if ( navigator.userAgent.search("Firefox") > -1 ) { | |
const link_elements = document.querySelectorAll('link[rel="preload"]'); | |
if ( link_elements.length ){ | |
link_elements.forEach( link => { | |
if (link.getAttribute('as') == 'style') { | |
link.setAttribute( 'rel', 'stylesheet' ); | |
} | |
} ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment