Improve script performance

This commit is contained in:
R. Miles McCain 2020-04-24 13:39:25 -04:00
parent 3f7aaa8f0d
commit 39ef4c9645
No known key found for this signature in database
GPG Key ID: 24F9B6A2588C5408

View File

@ -4,6 +4,9 @@ window.onload = function () {
Math.random().toString(36).substring(2, 15); Math.random().toString(36).substring(2, 15);
function sendUpdate() { function sendUpdate() {
try { try {
if (document.hidden) {
return;
}
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open( xhr.open(
"POST", "POST",
@ -21,8 +24,8 @@ window.onload = function () {
window.performance.timing.navigationStart, window.performance.timing.navigationStart,
}) })
); );
} catch {} } catch { }
} }
setInterval(sendUpdate, Number("{{heartbeat_frequency}}")); setInterval(sendUpdate, parseInt("{{heartbeat_frequency}}"));
sendUpdate(); sendUpdate();
}; };