In my build (for a complex webapp), I've aggregated all the javascript into 1 file, which I'm loading as script.js
I thought I might go even further and just print all the js into html. Are there any reasons I should not do that? My thinking is... why not just save the request?
The only downsides I'm aware of are: I understand that since the js is pretty huge, the initial page load might get slowed down.
I'm not very concerned about that since the page is empty anyway without javascript.
Also the script.js could be cached. If I wanted to cache the script within the html, I would have to use varnish or the like.
What are some reasons why I should not do this? Thanks.
Edit: I forgot to mention that this is a 1 page javascript app, so every single page has the same javascript (and html).
I use one single minified external js file. As a seperate file it can be cached nicely, although an extra HTTP request is needed.
If you put your java script inline then it wont be cached as simply and you will have duplication of code on every page if you are reusing methods that are inline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With