From 2a1a09062f8d5081a318b995e1a0459755716bb5 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 18 Apr 2015 11:07:36 +0300 Subject: [PATCH] Do not request server time when page has no timers --- js/90-timers.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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(); + } }); -- 2.39.2