45 ms·
What's wrong with just putting the script tag before the closing body tag?
by Kiro 13y ago
What's wrong with just putting the script tag before the closing body tag?
- mcmillion 13y agoCouple this with the fact that you should already be concatenating and minifying your assets, and this seems like a no-brainer. I suppose you could argue that this approach helps with CDNs, but therein lies another issue of whether or not serving a library from a CDN really buys you anything over just including it with your site's script payload.
- couchand 13y agoFWIW serving libraries from CDN cache buys you and your users and the whole of the internet bandwidth and electricity.
- igrigorik 13y agoIf you put a blocking script at the bottom you're still stuck waiting for CSSOM. If you put a script-injected tag at the bottom you're also blocked on CSSOM and your script is not discoverable by the preloader. For more details , see the comparison table in the post.
- Kiro 13y agoI'm not talking about a script injected tag, just a normal tag which doesn't block CSSOM. If you put them right before the closing body tag you address both the CSSOM issue and the DOM blocking since the DOM has already been processed. I understand that async also enables quicker execution of the script. What I don't understand however is why anyone would use script injection when you can just put the script tag at the bottom of the page to avoid DOM blocking. What am I missing?
- deleted 13y ago[deleted]