6gibsg
Last Updated: February 25, 2016
·
1.154K
· idered
190043 533696520020804 1840519452 n

Bind css refresh to custom key shortcut in chrome

I like LiveReload or SoFresh tools for reloading css but those tools doesn't always work or works bad with a lot of stylesheets attached. Here's a simple instruction how to bind custom shortcut to css reload function:

Download Shortcut Manager

In SM settings set custom shortcut.

"Action" set to "Execute JavaScript" and paste this code in the "(2)" field:

var links = document.getElementsByTagName("link");

for(var i = 0; i < links.length; i++) {
    var link = links[i];
    if(link.rel === "stylesheet")
        link.href = link.href.replace(/\.css.*/, '.css?reload=' + new Date().getTime());
}

Set custom description

That's all! I hope it will help you :)

Cheers!

Reload code is modified version from stackoverflow topic, thanks Claude for sharing non jQuery version.

Say Thanks
Respond

2 Responses
Add your response

3805

If you're doing this from an editor to a webpage, maybe have this triggered on a focus() event of the page in question?

over 1 year ago ·
18906
F8c44c0b34eba12c6e3928d90e36cfb5

If you don't want to install shortcut manager, you can also simply add it as a bookmarklet: http://ted.mielczarek.org/code/mozilla/bookmarklet.html

over 1 year ago ·