I am looking to implement a web page hit counter so that the server knows which pages are being viewed, where I try to avoid sending repeated "user hits" to the server by the same user on the same page. (I'm not really worried that they clear their cache, etc. And maybe counted again)
I usually saw something like this:
<img src="/the-hit-counter?pageId=SOME_PAGE_ID" />
then use a cookie to make sure that the "hit" does not count again.
But is there any reason not to use AJAX to notify the server, other than the obvious "the user must have JavaScript enabled"? I assume that almost everyone who does not wear a tin foil hat will be included in their browser these days.
With AJAX and JavaScript, I could do something like this and bring the local storage into a mix and reduce some network bandwidth:
if (!amplify.store('SOME_PAGE_ID')) { $.get('/the-hit-counter?pageId=SOME_PAGE_ID'); amplify.store('SOME_PAGE_ID', ""); }
What am I missing regarding the JavaScript approach?
source share