If I'm interested in the performance boost, can the second block be executed faster?
Since the scripts will be downloaded and executed asynchronously, yes, it will reduce the page loading time.
Author of the Script-injected "async scripts" considered harmful compares three methods of including a script: an injected script, a blocking script and a script with async
attribute. The result is:
script execution onload
----------------- ------------------ --------
script-injected ~3.7s ~3.7s
blocking script ~2.7s ~2.7s
async attribute ~1.7s ~2.7s
As you see, the async
attribute gives the best performance. If scripts execution order doesn't matter, you should definitely use it.
As for your title question:
Do browsers execute loaded scripts in a single thread?
Yes, because JavaScript is single-threaded, but it doesn't matter in terms of performance. Downloading a script takes much longer time than actually executing it, so you should focus on optimizing the download part.
I've made a test. I created a simple script:
for (var i = 0; i < 1e8; i++);
I put the same script into two files, test1.js
and test2.js
. Then I made two HTML files, the first without async
and the second with:
test1.html
:
<!DOCTYPE html>
<script src="test1.js"></script>
<script src="test2.js"></script>
test2.html
:
<!DOCTYPE html>
<script src="test1.js" async></script>
<script src="test2.js" async></script>
Then I opened these HTML files in my browser and checked Timeline tab in Chrome DevTools:
test1.html
:

test2.html
:

As you see, in both cases scripts are not executed asynchronously.
See also: Is JavaScript guaranteed to be single-threaded?.