Skip to content

Instantly share code, notes, and snippets.

@deckarts
Created February 6, 2022 19:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckarts/ea1f965306e0ed76df13239599bb3fa0 to your computer and use it in GitHub Desktop.
Save deckarts/ea1f965306e0ed76df13239599bb3fa0 to your computer and use it in GitHub Desktop.
const unblockCSS = () => ({
element: (el) => {
el.removeAttribute('media');
el.setAttribute('rel', 'preload');
el.setAttribute('as', 'style');
el.setAttribute('onload', "this.onload=null;this.rel='stylesheet';this.media='all'");
el.after(`
<noscript><link rel="stylesheet" href="${el.getAttribute("href")}"></noscript>
`, { html: true }); }});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment