前端技术如火如荼的状况下 浏览器兼容如何考虑

谈到兼容问题,主要指的是IE浏览器 随着ECMAScript5/6和h5,css3的普及 ,愈来愈多框架、库再也不支持老旧(如IE9如下)浏览器。css

先来看下2017.1-2017.6 各浏览器版本份额(数据来源:http://tongji.baidu.com/data/browser) 输入图片说明html

  • meta设置 <meta http-equiv="X-UA-Compatible"content="IE=edge,chrome=1">
  • 在样式表里添加hack的行为过于碎片化
  • ieBetter.js-让IE6-IE8拥有IE9+,Chrome等浏览器特性
  • Respond.js-让IE8识别Media Query ;
  • css-pie 让IE8支持css3部分特性
  • html5shiv 让IE识别h5新标签 (nav, header等)

给html添加条件注释html5

<!--[if lte IE 6 ]><html class="ie ie6 lte_ie7 lte_ie8 lte_ie9" lang="zh-CN"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7 lte_ie7 lte_ie8 lte_ie9" lang="zh-CN"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8 lte_ie8 lte_ie9" lang="zh-CN"> <![endif]-->
<!--[if IE 9 ]><html class="ie ie9 lte_ie9" lang="zh-CN"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="zh-CN"> <!--<![endif]-->

把ie补丁都写在个专门的fixie.css里。 这样样式文件干净 看着不心烦。jquery

若是 不考虑低版本IE ,能够插段代码,提示使用老旧浏览器的用户升级。 好比jquery插件的有:iealert.js,固然也可本身写js来判断css3