livereload: Close connection on pageshow

Fixes #13287
This commit is contained in:
Bjørn Erik Pedersen 2025-01-21 14:33:07 +01:00
parent 4b0c194fb3
commit d337619a01
No known key found for this signature in database
2 changed files with 21 additions and 7 deletions

View file

@ -31,4 +31,18 @@ HugoReload.prototype.reload = function (path, options) {
return true;
};
LiveReload.addPlugin(HugoReload);
(function () {
LiveReload.addPlugin(HugoReload);
// Close the WebSocket connection when the user leaves.
window.addEventListener('pagehide', () => {
console.log('Disconnecting LiveReload');
LiveReload.connector.disconnect();
});
// Open the connection when the page is loaded or restored from bfcache.
window.addEventListener('pageshow', () => {
console.log('Connecting LiveReload');
LiveReload.connector.connect();
});
})();

File diff suppressed because one or more lines are too long