Current location: Hot Scripts Forums » General Web Coding » JavaScript » Invoke up to 6 .js files into one


Invoke up to 6 .js files into one

Reply
  #1 (permalink)  
Old 12-07-07, 08:37 PM
Devİre Devİre is offline
Newbie Coder
 
Join Date: Oct 2007
Location: Portugal
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Post Invoke up to 6 .js files into one

Hello,

I'm building a newspaper site and I have up to 6 and up to more .js files been called up this way:

Code:
<script src="http://www.domain.com/jvs/script.js" type="text/javascript">
How can I place all of them on one single .js file, that later on can be placed on the page's <head></head> tags invoking all of them at once, I mean, instead of having loads of .js inclusions on the page, I would have one, that calls the main .js on which it calls all the others?

May seem a bit confusing
Reply With Quote
  #2 (permalink)  
Old 12-08-07, 07:53 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
You have a few options...

You can either call the other .js file automatically, or call it only if needed:

javascript Code:
  1. /* call the other .js automatically */
  2. document.write('<script type="text/javascript" src="secondScript.js"><\/script>')
  3.  
  4. /* place logic behind it and call only if needed */
  5.  
  6. /*load method:
  7.    newScript("secondScript.js"); */
  8.  
  9. function newScript(js_src) {
  10.      var js = document.createElement('script');
  11.      js.type = 'text/javascript';
  12.      js.src = js_src;
  13.      document.getElementsByTagName('head')[0].appendChild(js)
  14. }
However, if you are always going to be calling the same ones, I would suggest putting them all in one .js file. This will help speed as the client will only make one HTTP request for the scripts, rather than 6 separate ones.
__________________
"Political Correctness is a doctrine, fostered by a delusionary, illogical, liberal minority and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end."
Reply With Quote
  #3 (permalink)  
Old 12-08-07, 09:31 AM
Devİre Devİre is offline
Newbie Coder
 
Join Date: Oct 2007
Location: Portugal
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
One last question, the second option, the.js is called when its needed, automatically, right?

I mean, if the script is required by any plugin, it just call it up without to have to be implemented manually?
Reply With Quote
  #4 (permalink)  
Old 12-08-07, 09:34 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
No, you have to call it manually. But you can check it via logic. The call:

javascript Code:
  1. newScript("secondScript.js");
__________________
"Political Correctness is a doctrine, fostered by a delusionary, illogical, liberal minority and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end."
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
script to allow download of all files in a directory tomgardner Script Requests 2 10-15-06 07:47 PM
Check uploaded files size zoliky PHP 5 09-27-06 01:52 PM
How to differenciate Newly created files from old files in a directory itssami PHP 1 08-14-06 09:41 AM
netadmin project - delete files georgeminton Visual Basic 0 03-03-04 04:03 PM
How to do fopen all files at a time and show one line from all files. Mouse PHP 0 03-01-04 08:33 PM


All times are GMT -5. The time now is 11:32 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.