Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good Practice with External JavaScript files

Tags:

javascript

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!

like image 678
Georges Krinker Avatar asked Jan 15 '23 00:01

Georges Krinker


1 Answers

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.

like image 103
alemangui Avatar answered Jan 24 '23 15:01

alemangui