Skip to content

Instantly share code, notes, and snippets.

@diegosomar
Created March 18, 2020 14:10
Show Gist options
  • Save diegosomar/d1b86a77a9a99dd6ca6527072c8df946 to your computer and use it in GitHub Desktop.
Save diegosomar/d1b86a77a9a99dd6ca6527072c8df946 to your computer and use it in GitHub Desktop.
Enable Firefox compatibility to link[rel="preload"]
/**
* 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