Created
September 23, 2012 04:00
-
-
Save twolfson/3768822 to your computer and use it in GitHub Desktop.
Better File-Watcher
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 () { | |
var watcher = new FileWatcher(), | |
resources = ResourceCollector.collect(); | |
watcher.addListener(function (url) { | |
// If the updated item is CSS | |
if (url.indexOf('css') !== -1) { | |
// Grab all of the links | |
[].slice.call(document.querySelectorAll('link')).forEach(function (link) { | |
// If the link's href matches, update it | |
var href = link.href; | |
if (href.indexOf(url) !== -1) { | |
link.href = href + (href.indexOf('?') === -1 ? '?' : '') + 1; | |
} | |
}); | |
} else { | |
// Otherwise, reload | |
location.reload(); | |
} | |
}); | |
watcher.watch(resources, 8); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment