]> iEval git - gruntmaster-page.git/commitdiff
Do not request server time when page has no timers
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 18 Apr 2015 08:07:36 +0000 (11:07 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 18 Apr 2015 08:52:00 +0000 (11:52 +0300)
js/90-timers.js

index e03ae08dcf3171a13ad872225f1a94da512d0efa..c9b095039873c84b3f886eaaac06c2b48ee510d7 100644 (file)
@@ -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();
+       }
 });
This page took 0.023386 seconds and 4 git commands to generate.