Skip to content

Commit

Permalink
fix: live reload delay (#1822)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwagner authored Aug 25, 2023
1 parent d60191e commit 107dc61
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lucky/tags/live_reload_tag.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module Lucky::LiveReloadTag
def live_reload_connect_tag : Nil
def live_reload_connect_tag(ms : Int32 = 1000) : Nil
{% if flag?(:livereloadws) %}
tag "script" do
raw <<-JS
(function() {
var ws = new WebSocket("ws://#{Lucky::ServerSettings.host}:#{Lucky::ServerSettings.reload_port}");
ws.onmessage = function() { location.reload(); };
ws.onmessage = function() {
setTimeout(function() {
location.reload();
}, #{ms});
};
})();
JS
end
Expand All @@ -14,7 +18,11 @@ module Lucky::LiveReloadTag
raw <<-JS
(function() {
var stream = new EventSource("http://#{Lucky::ServerSettings.host}:#{Lucky::ServerSettings.reload_port}");
stream.onmessage = function() { location.reload(); };
stream.onmessage = function() {
setTimeout(function() {
location.reload();
}, #{ms});
};
})();
JS
end
Expand Down

0 comments on commit 107dc61

Please sign in to comment.