Skip to content

Instantly share code, notes, and snippets.

@zoras
Forked from kdzwinel/reloadCSS.js
Created August 16, 2017 03:54
Show Gist options
  • Save zoras/ae912904330c333104047135261f3a7c to your computer and use it in GitHub Desktop.
Save zoras/ae912904330c333104047135261f3a7c to your computer and use it in GitHub Desktop.
Reload CSS files without reloading the page
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