I was wondering if there is a good reference to how best to format .js files?
Do you treat them like you would class files or do you separate out the functionality based off the page it handles? Do you create .js functions that could be used across several pages or do you write a custom .js file for each page?
I'm just curious if there is a formal way rather than just writing a bunch of functions that may or may not be group together for a specific page or set of pages. Right now I try to group by the functionality of the page but my .js files are very custom for that page, not sure if they are usable on a different page.
::UPDATE::
Some of the answers have the same theme and mostly about what you plan on doing with the project. Right now the project is real new to me and the requirements are slow in coming. So I'm building it page by page. There could be cross functionality or similar functionality in the future. Most of the functionality is very specific to the specific page though.
Is it wise to group AJAX calls into a .js but then also have a custompage .js that contains all of the very custom features of the page.
Typically with javascript you'll want to reduce the amount of separate javascript files you include on your pages to reduce HTTP requests.
A great starting point would be for you to watch Rebecca Murphys building apps with jQuery presentation and read her blog post about using objects to organize your js.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With