And if so where would I put the second page of code. From reading some of the other questions here I finally realized that I needed to separate my javascript(jquery) code from my html which also helped with using a variable from one file to the next, however I have a second page of javascript(jquery) and I'm not sure how I should organize it all? or should I simply make another .js file for the second page? and then have two tags to both files?
-
2This is not a question, it is a lot of questions and a mess. Think out what you want to ask and be specific. A jumble like this won't get good answers. See the [faq]Hogan– Hogan2013-01-25 18:55:07 +00:00Commented Jan 25, 2013 at 18:55
-
Yeah, if this wasn't my FIRST time doing this type of programming I would have been more specific. Didn't really know what to ask since I don't know what protocols or design methods to use. MORE SPECIFICALLY can I put my second page of javascript code at the end of my first page of js code in the same file????jc72– jc722013-01-25 21:36:25 +00:00Commented Jan 25, 2013 at 21:36
3 Answers
No, no, no, write organized and readable code. Separate HTML, CSS and JS code, assets and keep them well organized.
see this How to organization JavaScript code in project for maintainability?
5 Comments
If you use jquery, you should use the file hosted by Google, because Google's connection is so fast and lots of people use that file, so it is likely that your client's browser will have the file in its caché (and this way you avoid downloading, so your page will load faster).
For more information, read http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/
And the js code which is not the jquery library, it doesn't matter very much if you use a single or multiple files, but I guess that each file needs a new request with all its headers. Then, avoid having very small .js files, join them instead.
Comments
You should organize you JS by functionality and than decide in each page what to load based on the functionality that you need, A good example is with jQuery plugins. You can have a file that load the jQuery plugins with all the configuration that you need and include that file every time that you need to use the plugin.
You can that create a .js file with all th functionality for the specific page. You will load that js only in the page that requires that functionality.
You can load JS file also in the js code by calling jQuery,getScript()
I hope this was useful and clear