# CSS会阻塞后面js语句的执行

<!DOCTYPE html>
<html lang="en">
<head>
  <title>css阻塞</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script>
    console.log('before css')
    var startDate = new Date()
  </script>
  <link href="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<h1>这是红色的</h1>
<script>
  var endDate = new Date()
  console.log('after css')
  console.log('经过了' + (endDate -startDate) + 'ms')
</script>
</body>
</html>

# css不会阻塞dom树的解析,会阻塞dom树的渲染

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>css阻塞</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
      p {
        color: red
      }
    </style>
    <script>
      function h () {
        let $p = document.getElementById('p')
        console.log($p)
        $p.style.color = '#247aff'
      }
      setTimeout(h, 2000)
    </script>
    <link href="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap.css" rel="stylesheet">
  </head>
  <body>
    <p id="p">这是红色的</p>
  </body>
</html>