3

After discussing it with a colleague, we need an answer to the question: Is a script in the footer "render-blocking"? I mean, is any content showed to the user before the script is completely loaded?

Thank you

AgoHH
  • 180
  • 1
  • 14

3 Answers3

3

It is coming late but I found the answer: No, a script is not render-blocking, a script is parse-blocking. Only CSS files are render-blocking.

If the script is inside the body, it will be parse-blocking but the content parsed before the script can already be rendered (if it is in the head nothing will be rendered because no content has been parsed yet). So, yes, content can be showed/rendered before the script is completely downloaded.

Please, see these two examples:

Screenshot Test1: Content rendered before the large JS file finishes downloading

<!DOCTYPE html>
<html lang="en"> 
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <link rel="stylesheet" href="css/style.css">
</head>
<body>
 <section>
  <h2>testing</h2>
  <h4>Lorem Ipsum has been the industry's standard dummy text printer took a galley of type and scrambled</h4>
  <img src="img/icon_128.png" width="128px" alt="">
  <h3>We are testing</h3>
  <p>Lorem Ipsum is simply dummy text of the printing and typesf own printer.</p>
 </section>
 <script src="js/main.js"></script>
</body>
</html>

Screenshot Test2: Content before the large JS file is rendered. The rest has to wait until the JS finishes downloading

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <link rel="stylesheet" href="css/style.css">
</head>
<body>
 <section>
  <h2>testing</h2>
  <h4>Lorem Ipsum has been the industry's standard dummy text printer took a galley of type and scrambled</h4>
  <img src="img/icon_128.png" width="128px" alt="">
  <script src="js/main.js"></script>
  <h3>We are testing</h3>
  <p>Lorem Ipsum is simply dummy text of the printing and typesf own printer.</p>
 </section>
</body>
</html>
AgoHH
  • 180
  • 1
  • 14
1

When you place javascript in the footer of the page; i.e. before the closing</body> without hte defer/async attribute then it is render blocking.

When the browser constructs the DOM and reads a script tag even in the footer and without the defer/async attribute, then, the browser can only continue the construction of the DOM if the script is completely downloaded.

Note that the DOM construction is not yet visible in the browser, until the browser paints the result.

The browser goes to 4 major steps before we can actually see the results.

  1. DOM and CSSOM constructions.
  2. Render Tree
  3. Layout - computes the exact position and size of each object.
  4. Paint - is the last step; renders the resulting pixels to the screen.

Links for Removing Render-Blocking Javascript and Render-tree Construction, Layout, and Paint

Den Isahac
  • 1,335
  • 11
  • 26
-2

Generally, every script is a blocker, but it is better to hold js in the footer.

Html page is executed by browser line by line as like as your code. If your script will be in the footer - that means that everything that before this script - is already rendered.

qiAlex
  • 4,290
  • 2
  • 19
  • 35