Working with a blog where the landingpage contains a large list of posts and 20-30 placeholder-divs for ads, each ad-div containing a script tag with a single function call that triggers the ad-loading.
For example: <script>initializeAd('ad-1')</script>
The function itself doesn't take any significant amount of time at all, it just appends the string argument to an array. The actual loading of ads occurs asynchronously later.
Now I'm tasked with improving the initial pageload speed and first-time-to paint, and what I'm wondering is: Does having 30 script blocks in the body have a negative impact on performance?
I know the browser has to interrupt HTML-parsing and start Script-evaluation as soon as it encounters a script block. But does the amount of script-blocks in itself have a negative effect? Is it costly for the browser to task switch from HTML parsing to script evaluation?
Could I improve the performance by simply moving all the code to a single script block at the end of body instead of having multiple script blocks?
Aucun commentaire:
Enregistrer un commentaire