I have a page with a javascript file at the end. the file is placed at the end so that I get access to all the dom elements.
let us say the markup looks like this

```
<html>
<head></head>
<body>
//lot of markup here
<script src="my-js.js"></script>
<body>

```

the sample markup is just to show the location of my js file.

the first like in the js file (my-js.js) is 

```
document.body.style.visibility = 'hidden';

```

After the code runs I set the visibility back to hidden

From what I have understood(from a lot of articles related to this including in stackoverflow ones) is that the browser reaches the js, then executes it, and then continues with render and then paints.
If that was true, my code as described should work fine.

However, what is happening now is that, the page is shown (for less than 500ms) as it is before the code executed, then quickly hidden and then shown again after the code executed.

in short, what I want is:
page is hidden > code executes > page is shown
instead what I get is
page is shown > page is hidden > code executes > page is shown

My question is why is the page shown for that split second? what am I doing wrong here?

PS: Please note that I cannot change the location of the js nor add another. So, do not post any solution that suggest the same. 
More importantly, I want to know why my code is wrong.