-
-
Save DorkNstein/06541daf723222b31183b0686af2fc2f to your computer and use it in GitHub Desktop.
Reload CSS files without reloading the page
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
function reloadCSS() { | |
const links = document.getElementsByTagName('link'); | |
Array.from(links) | |
.filter(link => link.rel.toLowerCase() === 'stylesheet' && link.href) | |
.forEach(link => { | |
const url = new URL(link.href, location.href); | |
url.searchParams.set('forceReload', Date.now()); | |
link.href = url.href; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment