Georges Krinker Georges Krinker - 21 days ago 7
Javascript Question

Good Practice with External JavaScript files

I'm new to JavaScript.

How should I split my functions across external scripts? What is considered good practice? should all my functions be crammed into one external

.js
file or should I group like functions together?

I would guess more files mean more HTTP requests to obtain the script and that could slow down performance? However more files keep things organized: for example,
onload.js
initializes things on load,
data.js
retrieves data from the server,
ui.js
refer to UI handlers...

What's the pros advice on this?

Thanks!

Answer

As Pointy mentioned, you should try a tool. Try Grunt of Brunch, both are meant to help you in the build process, and you can configure them to combine all your files when you are ready for prod (also, minify, etc), while keeping separate files when you are developing.