Go Back   DN Lodge Webmaster Forums > Web Design and Development > Web Development Discussion


Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-06-06, 11:10 PM
Geoserv's Avatar
Co-Admin
DNLodge Staff
Recent Blog: HostingCon 2009
 
Join Date: May 2006
Location: Nova Scotia, Canada
Posts: 2,133
DNL Trust: (0)
Geoserv has a helpful personalityGeoserv has a helpful personality
Default Putting JavaScript in an external .js file

Cut all code between the <script> and </script> tags and paste it to a .js file. Don't include HTML commenting (<!-- and -->), or any other HTML tags. To include the file on the page, use this code:

Code:
<script type="text/javascript" src="filename.js"></script>
Make sure the path to the .js file is correct.

Helps keep your coding cleaner.

Geoserv.
__________________
Latest Web Launches: Get In On! - Brand NEW!
Join me at - Second Brain
Top Stumbles |News Dots |APNAOnline | Utopian Productions |Pliggs |DIY Pad
|FAQ Pal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Want to remove these ads? Register for your free account here.

  #2  
Old 10-07-06, 03:39 AM
Jerlene's Avatar
This is my user title.
 
Join Date: Mar 2006
Posts: 3,168
DNL Trust: (1)
Send a message via AIM to Jerlene Send a message via MSN to Jerlene Send a message via Yahoo to Jerlene
Jerlene has a helpful personalityJerlene has a helpful personality
Default Re: Putting JavaScript in an external .js file

What exactly does this do and what are the benefits?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 10-07-06, 12:46 PM
Yowser's Avatar
DNL Addict
 
Join Date: Aug 2005
Location: St. Louis Missouri
Posts: 1,816
DNL Trust: (0)
Send a message via AIM to Yowser Send a message via MSN to Yowser Send a message via Yahoo to Yowser
Yowser is a pretty decent person
Default Re: Putting JavaScript in an external .js file

Moving your javascript to an external file takes it out of the way so that search engine spiders will have an easier time getting to the part that matters in your HTML pages. It can improve your rankings and make it easier for the SE's to index all the pages of your site.

I'm sure there are other benefits other than from an SEO standpoint but that is the major benefit.
__________________
There's a fine line between fishing and just standing on the shore like an idiot. - Steven Wright
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 10-07-06, 01:07 PM
Alter Ego
 
Join Date: Jan 2006
Posts: 562
DNL Trust: (0)
Send a message via MSN to linuxhq
linuxhq is making his way to the top
Default Re: Putting JavaScript in an external .js file

It mainly just helps you to organize your pages better code wise, and to allow the sharing of the same js code, for example a library, whithout having to insert it 600 times into all your files.
__________________

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 10-07-06, 08:18 PM
Geoserv's Avatar
Co-Admin
DNLodge Staff
Recent Blog: HostingCon 2009
 
Join Date: May 2006
Location: Nova Scotia, Canada
Posts: 2,133
DNL Trust: (0)
Geoserv has a helpful personalityGeoserv has a helpful personality
Default Re: Putting JavaScript in an external .js file

Yeah it keeps your coding cleaner, and it works just like CSS, can be shared on more than one page, and with one change it will change on all pages using it.

Geoserv.
__________________
Latest Web Launches: Get In On! - Brand NEW!
Join me at - Second Brain
Top Stumbles |News Dots |APNAOnline | Utopian Productions |Pliggs |DIY Pad
|FAQ Pal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 10-11-06, 06:00 PM
DNL Member
 
Join Date: Jul 2006
Posts: 10
DNL Trust: (0)
PunjabiSingh is a pretty decent person
Default Re: Putting JavaScript in an external .js file

Quote:
Originally Posted by Yowser View Post
Moving your javascript to an external file takes it out of the way so that search engine spiders will have an easier time getting to the part that matters in your HTML pages. It can improve your rankings and make it easier for the SE's to index all the pages of your site.

I'm sure there are other benefits other than from an SEO standpoint but that is the major benefit.
i like this idea, it makes sense, hope it is really an improvement.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 10-11-06, 11:37 PM
khasmoth's Avatar
DNL Member
 
Join Date: Oct 2006
Posts: 56
DNL Trust: (0)
khasmoth is a pretty decent person
Default Re: Putting JavaScript in an external .js file

Quote:
Originally Posted by Geoserv View Post
Cut all code between the <script> and </script> tags and paste it to a .js file. Don't include HTML commenting (<!-- and -->), or any other HTML tags. To include the file on the page, use this code:

Code:
<script type="text/javascript" src="filename.js"></script>
Make sure the path to the .js file is correct.

Helps keep your coding cleaner.

Geoserv.
Thanks for this information Geoserv. This is very useful to all Javascript user.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 10-16-06, 09:52 AM
DNL Member
 
Join Date: Oct 2006
Posts: 11
DNL Trust: (0)
Jell-O-Fishi is a pretty decent person
Default Re: Putting JavaScript in an external .js file

you can take this a step further. take out all the onclick events and whatever javascript you've inserted into html tags, and create a function (in a separate file ofcourse) that will attach those events to the html tags of the right type with the right id (and possibly by calss too, not that complicated). the more separation between content and fucntionality the better. same with css, try to use the style addtirbute as less as possible.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 10-19-06, 06:40 PM
DNL Member
 
Join Date: Oct 2006
Posts: 26
DNL Trust: (0)
irunbackwards is a pretty decent person
Default Re: Putting JavaScript in an external .js file

Usually you will put this in your HEAD tags too. I like using this for longer .js files, so my main html or php page looks more clean-cut.

If it is a short bit of js though I will just include it on that page, unless I need to use on multiple pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10  
Old 10-19-06, 07:39 PM
DNL Member
 
Join Date: Oct 2006
Posts: 11
DNL Trust: (0)
Jell-O-Fishi is a pretty decent person
Default Re: Putting JavaScript in an external .js file

not sure if it's just firefox, but is it correct that <script src="whatever.js" /> isn't valid, only <script src="whatever.js"></script> (i mean the fact that the closing tag has to be separated)
or is this just a matter of the dtd i use.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11  
Old 10-19-06, 08:08 PM
Geoserv's Avatar
Co-Admin
DNLodge Staff
Recent Blog: HostingCon 2009
 
Join Date: May 2006
Location: Nova Scotia, Canada
Posts: 2,133
DNL Trust: (0)
Geoserv has a helpful personalityGeoserv has a helpful personality
Default Re: Putting JavaScript in an external .js file

It depends on the DTD, XHTML requires a you to close the tag all in one.

Geoserv.
__________________
Latest Web Launches: Get In On! - Brand NEW!
Join me at - Second Brain
Top Stumbles |News Dots |APNAOnline | Utopian Productions |Pliggs |DIY Pad
|FAQ Pal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
external, file, javascript, putting


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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
I can't open my data file as I tested file does not exists Jax Web Design Discussion 1 08-24-06 03:53 PM


All times are GMT -5. The time now is 07:06 PM.



Copyright © 2005-2009 DNLodge.com.
vBulletin, © 2000-2009, Jelsoft Enterprises Limited.
SEO by vBSEO.
Advertising |  About Us |  Contact Us |  RSS |  Privacy Policy |  Back to Top