0 Replies Latest reply on Jan 13, 2012 11:02 AM by wesleyhales

    User-Agent or Feature detection (both server and client)

    wesleyhales

      There are multiple ways to parse the UA string both on the client and server, and I have been on the fence for a while. After reading these posts (and comments):

      --- http://blog.mobileesp.com/?p=237

      --- http://infrequently.org/2011/01/cutting-the-interrogation-short/

      --- http://farukat.es/journal/2011/02/499-lest-we-forget-or-how-i-learned-whats-so-bad-about-browser-sniffing

       

      We see that feature detection is the best way (imo) to know what the client device can do in terms of HTML5 apis. With that said; Can feature detection frameworks (like modernizr) be improved? Yes, they should. With a 30ms test suite execution every time you load the page, you are looking at additional overhead that could possibly be avoided.

       

      So, one should consider writing their own detection for only the features they need with something like:

       

      function detectCanvas() { 
      var canvas = document.createElement("canvas"); 
      return canvas.getContext ? true : false; 
      }
      
      

      For more see http://www.html5rocks.com/en/tutorials/detection/