Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any performance issues in having a large number of script tags in your html?

Are there any issues in having a large number (say 50) of script tags in an html file. Does it cause any performance issues in page rendering times?

I have a section on my page that's pulling a geolocation point and putting this into an array for use on a google map. I could create a separate query for just the geolocation points but I believe it is more efficient if I pull this out as other content is requested.

<script type="text/javascript">points[{count}] = [{job_latitude},{job_longitude},'{title}'];</script>
like image 755
proee Avatar asked Feb 09 '10 17:02

proee


2 Answers

When a browser encounters a SCRIPT elements it stops parsing and rendering the HTML and starts parsing and interpreting its contents. That is because the code SCRIPT elements could alter the already parsed DOM tree.

That’s the reason why it’s recommended to put SCRIPTs at the bottom of the document so that the whole document body is already parsed.

So I would rather request the geo locations altogether (maybe you can collect them on the server side and print them at the end). Or if you cannot or don’t want to do that, add the defer attribute to your SCRIPT elements to tell the parser not to wait for the script.

like image 86
Gumbo Avatar answered Nov 12 '22 21:11

Gumbo


LABjs is a lightweight .js file (MIT license) which will allow your script to load in parallel with the markup - it has the potential to significantly improve page load time - but be careful to make use of the wait() function to ensure dependencies are honoured.

like image 2
plodder Avatar answered Nov 12 '22 20:11

plodder