Doubt about where to put the JS script

0

I'm working on a dashboard for a website where you have two JS functions at the bottom of the page that will only be used on a page that will be opened in a modal.

On this site there is also a file dedicated only to scripts.

I would like to know if there are any problems I put these two functions only on this page because I will only use these functions in it, or I have to ALWAYS put in the .js file regardless if I will only use one page.

I'm wondering why I always put all the JS in this file, however, I KNOW (I do not know if it's the right one) that there's no need to be polluting more and more a file by putting a function that I'll only use on a page in the entire site.

What is the ideal way?

    
asked by anonymous 15.08.2017 / 15:30

2 answers

1

Renan, I think it all depends on common sense. What is the size of the application, etc. If you do not want to have a JS with all the functions, which I also do not like, you can segment the JS files according to your area / domain or features.

    
15.08.2017 / 15:39
1

I believe that a single file is better minimized than a new request every time the user accesses a page.

It's the same with sass. Use a processor to make imports easier and create a minimized final file with it.

Gulp, grunt and etc., help a lot.

Abs!

    
15.08.2017 / 16:00