[关闭]
@fengfeng 2014-09-19T03:03:19.000000Z 字数 789 阅读 1473

条件注释会阻塞页面渲染

IE条件注释


第一种情况

条件注释会阻塞页面的下载,直到css文件都下载了,才继续下载;
block further downloads until the css files are fully downloaded, hence increasing load time
例如:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link type="text/css" rel="stylesheet href="1.css">
  5. <!‐‐[if IE 6 ]>
  6. <link type="text/css" rel="stylesheet" href="ie.css">
  7. <![endif]‐‐>
  8. </head>
  9. ...

解决方法:在所有的css之前写一个空的条件注释 from1 from2

  1. <!DOCTYPE html>
  2. <!--[if IE]><![endif]-->
  3. <html>
  4. <head>
  5. <link type="text/css" rel="stylesheet href="1.css">
  6. <!‐‐[if IE 6 ]>
  7. <link type="text/css" rel="stylesheet" href="ie.css">
  8. <![endif]‐‐>
  9. </head>
  10. ...

第二种情况

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. ...
  5. </head>
  6. <!‐‐[if IE 6]><body class="ie6"><![endif]‐‐>
  7. <!‐‐[if !IE]><!‐‐><body><!‐‐<![endif]‐‐>
  8. ...

解决方法:把条件注释的class提前放到html上,不要放body上 from2

  1. <!DOCTYPE html>
  2. <!--[if IE6]><html class="ie6"><![endif] -->
  3. <!--[if !IE]><!--><html><!--<![endif]-->
  4. <head>
  5. ...
  6. </head>
  7. <body>
  8. ...
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注