Organize javascript code based on page

Hi I'm relatively new to javascript development. At the moment, I have one javascript file with a lot of small pieces of code that are called in another part of the website. For example, I have an event handler for some google map stuff that is only called on one individual page, I have some validation stuff for my contact page, etc. My question is - what is the best way to organize this code - given that each page only requires very small code, but its different and specific to the page?

Oh, I'm using jquery if it matters.

+2


a source to share


1 answer


If each page has nothing to do with your js file, and only a portion of it is used by each page, a good way would be to separate each of these pieces of js code for each page. This will just improve page loading slightly depending on the size of your javascript file.



+6


a source







All Articles