Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
});
}
@kdzwinel

This comment has been minimized.

Copy link
Owner Author

kdzwinel commented Jul 28, 2017

reloadcss mov

@stowball

This comment has been minimized.

Copy link

stowball commented Jul 29, 2017

You could use querySelectorAll('link[rel="stylesheet"]') to remove the need to filter()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.