summaryrefslogtreecommitdiff
path: root/source/infra/js/count.js
diff options
context:
space:
mode:
Diffstat (limited to 'source/infra/js/count.js')
-rw-r--r--source/infra/js/count.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/source/infra/js/count.js b/source/infra/js/count.js
index e7911ec..0271445 100644
--- a/source/infra/js/count.js
+++ b/source/infra/js/count.js
@@ -150,19 +150,23 @@
if (!url)
return warn('not counting because path callback returned null')
- var img = document.createElement('img')
- img.src = url
- img.style.position = 'absolute' // Affect layout less.
- img.style.bottom = '0px'
- img.style.width = '1px'
- img.style.height = '1px'
- img.loading = 'eager'
- img.setAttribute('alt', '')
- img.setAttribute('aria-hidden', 'true')
-
- var rm = function() { if (img && img.parentNode) img.parentNode.removeChild(img) }
- img.addEventListener('load', rm, false)
- document.body.appendChild(img)
+ if (navigator.sendBeacon)
+ navigator.sendBeacon(url)
+ else { // Fallback for (very) old browsers.
+ var img = document.createElement('img')
+ img.src = url
+ img.style.position = 'absolute' // Affect layout less.
+ img.style.bottom = '0px'
+ img.style.width = '1px'
+ img.style.height = '1px'
+ img.loading = 'eager'
+ img.setAttribute('alt', '')
+ img.setAttribute('aria-hidden', 'true')
+
+ var rm = function() { if (img && img.parentNode) img.parentNode.removeChild(img) }
+ img.addEventListener('load', rm, false)
+ document.body.appendChild(img)
+ }
}
// Get a query parameter.
@@ -267,3 +271,4 @@
goatcounter.bind_events()
})
})();
+