Skip to content

Instantly share code, notes, and snippets.

@cvan
Last active March 11, 2023 21:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cvan/8a188df72a95a35888b70e5fda80450d to your computer and use it in GitHub Desktop.
Save cvan/8a188df72a95a35888b70e5fda80450d to your computer and use it in GitHub Desktop.
check if a CSS stylesheet has loaded
var linkEl = document.head.querySelector('link[href*="/styles/index.css"]');
var cssLoaded = Boolean(linkEl.sheet);
linkEl.addEventListener('load', function () {
cssLoaded = true;
});
@Finesse
Copy link

Finesse commented Aug 16, 2018

This is enough:

function isCSSLinkLoaded(link) {
  return Boolean(link.sheet);
}

It work both for correct and incorrect CSS files.

@cvan
Copy link
Author

cvan commented Dec 3, 2019

@VAggrippino check the updated gist now. that should work.

@Finesse
Copy link

Finesse commented Dec 3, 2019

@VAggrippino What browser were you testing in?

@jgarcianewemage
Copy link

if(document.head.querySelector('link[href*="/index.css"]') != null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment