1

Good day everybody, I set a function to get the users country when he/ she visits my website for the first time thanks to a cookie and ajax in jQuery, this function takes about 800ms which provides a wrong page speed stats. I've did some research but didn't find a way to only execute this function when a real visitor access the website and not any crawler... I've checked with modernizr but they don't offer the possibility to tell the user agent. I also read about $.browser() but heard it's deprecated... Do you have any idea how to achieve this? thanks a lot

Websphere
  • 563
  • 8
  • 24
  • https://developer.mozilla.org/es/docs/Web/API/NavigatorID/userAgent But userAgent does not ensurely gives you the real browser, because you can edit by yourself the userAgent. All this functionality is deprecated because it's better to target capabilities instead of browser. – Marcos Pérez Gude Apr 05 '16 at 11:26
  • Thanks Marcos for your very fast reply :) I've already checked that link actually, and would like something that is not deprecated. What if i just want to know if it's a robot or crawler which is visiting the website? there is not easy way to do so? – Websphere Apr 05 '16 at 11:32
  • 1
    Possible duplicate of [Detect Search Crawlers via JavaScript](http://stackoverflow.com/questions/20084513/detect-search-crawlers-via-javascript) – Marcos Pérez Gude Apr 05 '16 at 11:33
  • That article solves your problem. Good luck!! :) – Marcos Pérez Gude Apr 05 '16 at 11:34
  • These solutions seem to be complicated and not reliable :/ is there any specific feature that can be checked using modernizr which doesn't exist in bots/ crawlers? – Websphere Apr 05 '16 at 12:18

1 Answers1

0

Did you find how to manage it?

Be aware that "the user agent string is becoming meaningless and extremely unreliable"* as explained here.

you can also check this library: https://github.com/faisalman/ua-parser-js

There are some interesting features requests:

Feature request: isBrowser

Feature request: detect crawler

Community
  • 1
  • 1
charlesdg
  • 814
  • 11
  • 18
  • hey @charlesdg, sorry I just saw your message. No i didn't manage it, I ended up by giving up :) but thanks very much for your link, I'll have a look at it ;) Cheers – Websphere Feb 06 '17 at 21:09