I have several questions that are somewhat related to each other, so I post them on one question about SO ...
Question 1:
I am currently doing this Facebook application, where I use jQuery UI Tabs, there are only 4, where 2 of them are loaded via Ajax. The main page is index.html, the tab code is located here, and for two tabs downloaded via Ajax, I have two different files: tab1.html and tab2.html.
Currently, jQuery tab initialization and JavaScript initialization in JavaScript is done on index.html. Both tab1.html and tab2.html have JavaScript code that belongs to these pages. For example, tab2.html has a form and there is JS code (with jQuery) for checking the form, this code is not related to tab1.html, since the JS code on tab1.html is not related to tab2.html.
My question is: should I continue to do this or maybe combine all the JS / jQuery code in index.html, tab1.html and tab2.html in one global.js file, and then include it in index.html?
Although I do this, irrelevant code will be loaded if the user never opens tab1 or tab2. The advantage of using a single global.js file is that I can pack / shrink the file, which I could not do by including each block of code in each corresponding tabX.html file.
Question 2:
Since I use jQuery, I also use a lot of plugins (actually only 3 at the moment, but this number can grow). Some of them provide mini JS, and I use those when they are available, when they are not, I use the regular versions, of course.
There is also a problem with queries. If I have many plugins, say 10, then there will be 10 requests for these plugins. And there is also the fact that some plugins are used in tab1.html, but not on tab2.html and vice versa.
How to load all plugins in mini-packaging / packaged version on one web request? Do I have to do this manually before publishing my application (with packaging and merging them into one file), or can I use the PHP version of Dean Edwards Packer and package / combine all the plugins on the fly? Would this be a good approach?
Question 3:
If the answer to Q1 was something like "merge all the code into one global.js file," should I include the global.js file in the packaging / merging script described above in Q2?
It will simplify everything. I could properly configure my development environment with all .js files, for plugins and global.js in the corresponding folders, without worrying about anything else. Packaging / merging should take care of the rest (pull out files from the appropriate folders, send the appropriate JS headers and output one single packed .js file).
The only thing that confuses me is that not all plugins are used for each tab, and not all the code for each tab. However, a piece of code is global for each tab and index. It also simplifies everything: a) I don’t have to worry to add the necessary code to each tabX.html file, and I can just look at them as HTML templates and nothing more; b) I don’t have to worry about including the necessary plugins where I need them, because I am currently using $ .getScript () from jQuery to load the plugins that I need when and only when I need them, but I'm not sure That is a good approach, and the code seems dirty and ugly like that.