10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/modules/reload.rb', line 10
def self.build_reload_js
<<~JS
var hash = null;
function checkForChanges() {
console.log("Check for file changes");
var response = new XMLHttpRequest();
response.open("GET", "/api/hash", true);
response.onload = function() {
if (response.status === 200) {
if (!hash) {
console.log("Set initial hash")
hash = response.responseText
}
if (response.responseText !== hash) {
location.reload();
}
}
}
response.send(null);
}
checkForChanges()
setInterval(checkForChanges, 1000);
JS
end
|