SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    Skills to Pay the Bills Sparkie's Avatar
    Join Date
    Jul 1999
    Location
    A cave with 47 computers and an internet feed
    Posts
    3,559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Combining all Javascripts into one

    Stupid question...
    Is it possible to combine all of the javascripts on your site into one offpage referenced .js file? That way search engines don't have to comb through all that code to get to the real content. Or will all of the scripts in one file just muck up all of them?

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it is possible but don't make this too large as for the first time it will be downloaded on the client machine so if it s too large then will take long time and may find time out error.
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  3. #3
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Very true, but once that file has been downloaded it will be cached by the browser thus speeding up subsequent page load times.

  4. #4
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes for subsequent hit it will be faster page loading.
    but still i don't use this method much as i need to upload 2 files everytime i do change in HTML elements.

    But yes this can be a good solution for the site which is not updated regularly.
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  5. #5
    Skills to Pay the Bills Sparkie's Avatar
    Join Date
    Jul 1999
    Location
    A cave with 47 computers and an internet feed
    Posts
    3,559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What method do you use instead?

    And how long can the file take to download before the person gets a timeout error? I only have a couple of scripts on the site.
    Sherice Jacob - Web Improvement Expert
    Improve Website Conversions | eBook Covers
    Follow Me on Twitter!

  6. #6
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    the file would have to be huge to cause any kind of an error. The page would just load slowly as the browser has to wait to download and then parse the javascript.

    I like to put as much code as I can into one file assuming it is common to a majority of pages. If it is specific to one page or just a handful, I still make it external but only link to it on those pages.

  7. #7
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if they are working on your site already, putting them into their own file wont make any difference to them whatsoever.

    Not sure what 'timeout' issues Vikrant is talking about, but I'd imagine your javascript file couldn't be any more than a few kb in size... and they have to download all of your javascript regarldess even if it's stored inline anyway.

  8. #8
    Skills to Pay the Bills Sparkie's Avatar
    Join Date
    Jul 1999
    Location
    A cave with 47 computers and an internet feed
    Posts
    3,559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what is the code I use to reference a javascript that's not within my pages. Is it similar to a stylesheet?

    <LINK REL=??? HREF="myscript.js" TYPE="???">

    Help me fill in the blanks, then I'll be all set Many thanks!

  9. #9
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    <script type="text/javascript" src="path/to/file.js"></script>

    Don't forget the closing </script> tag or else you'll generate an error.

    Good luck!

  10. #10
    Skills to Pay the Bills Sparkie's Avatar
    Join Date
    Jul 1999
    Location
    A cave with 47 computers and an internet feed
    Posts
    3,559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Stymiee!
    Sherice Jacob - Web Improvement Expert
    Improve Website Conversions | eBook Covers
    Follow Me on Twitter!

  11. #11
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    usa
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i just tried linking to an external .js file for a rotating image like this:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>quick links go here</title>
    <link rel="stylesheet" type="text/css" href="styles/soxStylesCSS.css">
    <script type='text/javascript' src='javascript/rotateImage.js'></script>
    
    </head>
    
    <body onload="rotateImage();">
    
    <div id="containerMain">
    
    <div id="headerL1>
    	<div id="nameplateL1>
    	</div nameplateL1>
    	<div id="rotatePic">		
    	<img id="imgRotating" src="images/soxImage1.gif" alt="Sarbanes-Oxley header image rotating series" width="195" height="128">			</div rotatePic>
    
    </div headerL1>
    
    </body>
    and the image does not rotate .

    this same scritp worked fine like this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>quick links go here</title>
    <link rel="stylesheet" type="text/css" href="styles/soxStylesCSS.css">
    
    <script language="javascript">
    	function rotateImage(){
    		eval("document.all.imgRotating.src = 'images/soxImage"+generate(1,5)+".gif';");
    	}
    	
    	function generate(x, y) { 
    		var range = y - x + 1; 
    		return Math.floor(Math.random() * range) + x; 
    	} 
    	
    </script>
    
    
    </head>
    
    <body onload="rotateImage();">
    
    <div id="containerMain">
    
    <div id="headerL1>
    	<div id="nameplateL1>
    	</div nameplateL1>
    	<div id="rotatePic">	
    	<img id="imgRotating" src="images/soxImage1.gif" alt="SarbanesOxley header image rotating series" width="195" height="128">
    	</div rotatePic>
    </div headerL1>
    
    </body>
    also, i have a drop-down script i want to use on some of the pages as well. from what i have read, i can combine both/all scripts into one file. but, can i link to multiple external javascript files, and if so, how?

    thank you :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •