Doubt about where to put the JS script

Asked

Viewed 46 times

0

I’m fiddling with a panel of a website that has two JS functions at the bottom of the page that will only be used on a page that will open in a modal.

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

I wonder if there is any problem 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 file . js regardless if I will use only on one page.

I ask because they always tell me to put all the JS in this file, however, I THINK (I don’t know if it’s right) that there is no need to pollute more and more a file by putting a function that I will only use on a page throughout the site.

What is the ideal shape?

2 answers

1

Renan, I think it all depends on common sense. What size application etc. If you don’t want to have a JS with all the functions, which I don’t like either, you can segment the JS files according to your area/domain or functionality.

1

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

It’s the same thing with Sass. Use a processor to facilitate Imports and create a minimized end file with it.

Gulp, Grunt and etc, help a lot.

Abs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.