Hacker News new | ask | show | jobs
by cont4gious 5732 days ago
Did I miss something, or why are these in your head tag? Why not put them in the body tag so they don't load until after the browser has rendered the page?
2 comments

Sorry, but you aren't right. Those are mostly located in body tag. They are requested as soon as encountered by browser, because they might issue "document.write", so the execution of rest of HTML is delayed until that "src" is loaded. That's exactly what causes the problem. Putting script into body doesn't defer its execution.

I'm not sure how browsers render <script src in head, but probably the same.

Works same in the head. All scripts if not set to asynchronous will prevent further rendering of the page until the script has finished loading and running.
oh, ok, thanks! i would have made the assumption that this would have fixed it and been frustrated.
Good point, but you'll still benefit from using async script loading if you have multiple third-party scripts loading at the end of your page. If the Twitter script is included before the others, and it lags, it will hold them up too.