From: Marius Gavrilescu Date: Sat, 18 Apr 2015 08:07:36 +0000 (+0300) Subject: Do not request server time when page has no timers X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=2a1a09062f8d5081a318b995e1a0459755716bb5;p=plack-app-gruntmaster.git Do not request server time when page has no timers --- diff --git a/js/90-timers.js b/js/90-timers.js index e03ae08..c9b0950 100644 --- a/js/90-timers.js +++ b/js/90-timers.js @@ -30,12 +30,14 @@ $(() => { update_timer(item); setInterval(() => update_timer(item), 1000); }); - let xhr = new XMLHttpRequest(); - xhr.open('HEAD', '/'); - xhr.onload = () => { - let srvtime = Date.parse(xhr.getResponseHeader('Date')); - offset = Math.ceil((srvtime - Date.now()) / 1000); - console.log("Offset from server: " + offset); - }; - xhr.send(); + if($('.timer').length > 0) { + let xhr = new XMLHttpRequest(); + xhr.open('HEAD', '/'); + xhr.onload = () => { + let srvtime = Date.parse(xhr.getResponseHeader('Date')); + offset = Math.ceil((srvtime - Date.now()) / 1000); + console.log("Offset from server: " + offset); + }; + xhr.send(); + } });