Is it possible to detect a browser's support for HTTP2/SPDY client-side from within the browser?
I am attempting to show users whether their browser supports HTTP2/SPDY or would use the traditional, non-HTTP2/SPDY HTTPs protocol.
Is it possible to detect a browser's support for HTTP2/SPDY client-side from within the browser?
I am attempting to show users whether their browser supports HTTP2/SPDY or would use the traditional, non-HTTP2/SPDY HTTPs protocol.
No, not really. At least in a way that is meaningful or actionable.
Frontend javascript would be running after the server has already served all of the assets. Everything you want to be doing will be done on the server side. A SPDY compliant browser should negotiate with a SPDY server automagically.
All you need to do is configure it to do so (nginx, and apache). You can also send the
Alternate-Protocol
header with your https responses. That would have the browser respond with SPDY requests in the future if possible (I can't find that in the updated SPDY spec, so that may be outdated information. Take with salt).If you wanted to know if a site has been served with SPDY, in chrome there is chrome.loadTimes().wasFetchedViaSpdy (obviously only works in chrome). For firefox and safari you would have to inspect the headers (as far as I know there is not a similar api, though plugins exist to do this for you). SPDYCheck is another great resource to test if the server has been setup correctly.
Thanks, Patrick. I took your advice and leveraged nginx's
$http2
variable and used PHP to return a dynamic JS variable for the browser's detection. (Passing a cookie or adding a response header for AJAX detection are also options if other readers prefer).NGINX config additions
detect-http2.js.php
detect-http2.html