views:

43

answers:

2

Hi I am relatively new to javascript development. At the moment I have a single javascript file with lots of little misc bits of code that get called in different part of the website. For example I have an event handler for some google maps stuff that is only called on 1 single page, I have some validation stuff for my contact page etc etc. My question, is how best to organise this code - given that each page only requires very little code but its different and specific per page?

Oh, I am using jquery if that makes a difference.

A: 

Check out this thread for information on caching JS files. The answer to that question has some good links on where I think you are heading.

qor72
+6  A: 

If there is nothing shared by each page from your js file and only a part of it is used by each page, the good way will be to separate each of those js code snippets for each page. This will simply improve page loading a little depending on the size of your javascript file.

Sarfraz