summaryrefslogtreecommitdiff
path: root/source/infra/js/count.js
diff options
context:
space:
mode:
authorPrefetch2023-07-09 15:30:02 +0200
committerPrefetch2023-07-09 15:30:02 +0200
commitb9a42ffcf1f00da5011487c0992129ae90372b4c (patch)
tree4734d8b8ec979fcfa2463f6cf57768625e0bb353 /source/infra/js/count.js
parent7530507686858f7b49a8be4fca4f5c55483e8b4f (diff)
Update KaTeX and GoatCounter, fix blog post sorting
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()
})
})();
+