Created
February 14, 2025 15:43
-
-
Save MarkTiedemann/78713fd56896c2e5ead70387f0460505 to your computer and use it in GitHub Desktop.
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 cssUrl = "/your.css"; | |
const cssRequest = await fetch(cssUrl); | |
if (!cssRequest.ok) { | |
throw new Error(`Failed to load '${cssUrl}' (status: ${cssRequest.status})`); | |
} | |
const cssText = await cssRequest.text(); | |
const styleSheet = new CSSStyleSheet(); | |
await styleSheet.replace(cssText); | |
document.adoptedStyleSheets = [styleSheet, ...document.adoptedStyleSheets]; | |
// CSS is ready to be used now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment