Ok, by big I mean like 300 lines un-minified. Not that big.
My question here tho is for the script file that is only ever loaded on one page, should I put it in the "general" script file that gets loaded on each page? Or should it be a seperate file itself?
One consideration I had was that I was told to reduce the number of http requests a page cause to decrease the load time.
So am I right to think that the trade off here are between less http request per page and more payload per page? Any other consideration I should be aware of?
For more background info, I have 2 piece of JavaScript that are only ever used on their respective page and about 10 pages total.
edit - 300 lines minified atm is 3kb.
One thing to consider is whether users will be visiting your pages on a regular or one-off basis. If the former, then the script will be cached and using one single large script will be a benefit because it will mean that there will only be a single server request to see if it has changed, rather than the multiple requests that will be required for multiple scripts. If the latter then overall download size (for each page) might be more important than number of elements.
A second point to consider is the size of the script compared to the overall download size of the other elements of the page.
A final point is how the page is constructed, if it is just a form or something similar then the size of the code might be relevant to page load speed, but if putting the page together involves complex database lookups then a few extra kB of JavaScript is the least of your concerns.
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