1、通过 nginx 来判断当前是否有 http2 变量,并通过 rewrite 转发到 php,
2、后端php 在判断,是否有 http2 参数,并返回js变量,
3、js 在检测是否有 http2
一、Nginx 配置如下
if ($http2) { rewrite ^/detect-http2.js /detect-http2.js.php?http2=$http2 last; } rewrite ^/detect-http2.js /detect-http2.js.php last;
二、PHP代码
<?php header('content-type: application/javascript'); if (isset($_REQUEST['http2'])) { echo "var h2Version='". $_REQUEST['http2'] . "';\n"; } ?>
三、前段代码
<html> <body> <script src="https://DOMAIN_NAME/detect-http2.js"></script> <script> document.write('HTTP2-Supported Browser: '+ (typeof h2Version !== 'undefined')); </script> </body> </html>
转载请注明:爱开源 » 检查浏览器是否 支持 HTTP2/SPDY