Skip to content

Instantly share code, notes, and snippets.

@twolfson
Created September 23, 2012 04:00
Show Gist options
  • Save twolfson/3768822 to your computer and use it in GitHub Desktop.
Save twolfson/3768822 to your computer and use it in GitHub Desktop.
Better File-Watcher
(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