I am trying to understand how CSS is evaluated in a specific setting:
Lets assume I have the following content in my <head>
tag:
<html><head>
...
<link href="reset.css" type="text/css" rel="stylesheet">
<link href="style.css" type="text/css" rel="stylesheet">
<link href="autocomplete.css" type="text/css" rel="stylesheet">
</head>
<body>
... html ...
<script type="text/javascript" src="/js/script.js"></script>
</body></html>
Now, let's assume reset.css
and style.css
contain some rules that immediately affect the above the fold content or the the elements in the HTML. However, autocomplete.css
only contains class used that are used later by some JavaScript.
Now, let's further assume the browser already downloaded reset.css
and style.css
but autocomplete.css
is still pending.
I am wondering what would happen if the browser would do it encounters the blocking script tag at the end of the page? Obviously, it can render the HTML up to the script tag, but is the execution of the script blocked by the missing autocomplete.css
?
Note that the script tag is not a sync.
I've read: https://developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp
And there it says that the execution of the JavaScript is blocked until the CSSOM is there.
Now:
1. Will the page start rendering even autocomplete.css
has not yet arrived? and,
2. Is the execution of the script.js
javascript blocked until the autocomplete.css
is there?
Note, I am referring to two different things: rendering and script execution.
autocomplete.css
is missing then the page will throw a silent error: Failed to load resource: net::ERR_FILE_NOT_FOUND. But everything will continue to load including your script. If the file exists and it is taking time to load then your page will not load since your css is in the head and it must be loaded before loading the rest of the page. – Incombustible