DelphiFAQ Home Search:

Advantages of keeping Javascript in include files

 

comments3 comments. Current rating: 4 stars (1 votes). Leave comments and/ or rate it.

Question:

Should I embed my javascript code in HTML files or should I use include files? My pages share only some of the Javascript code.

Answer:

Obviously the advantage of keeping the code in an external *.js file is more obvious the more code your pages share. But even if the overlap is limited there are some other benefits:

  1. Search engine spiders can crawl and index your site easier if they have less code to wade through. The spider software looks for your page content (text, titles, alt tags) and typically ignores the javascript.
    Another example that it pays to separate content and presentation. Note that if you use javascript do actually generate content on the fly using document.write() statements, then search engines most likely will not be able to see this content.
    This applies to navigation (menus, buttons..) and sometimes 'encrypted' email addresses, so the damage is rather limited.
  2. A search engine may look what percentage of the whole document the keywords make of. If 30% of your document are javascript, then content related to your keywords makes up only 70%. If all your javascript would be in an external 'include' file, then your keywords will appear more 'relevant'.
  3. For a visitor the page may load *slightly* faster with javascript include files. Depending on the web browser, the document itself will load right away and then multiple connections to your web server will fetch images and javascript include files. The web page may be rendered before the javascript is loaded.


Comments:

2006-05-31, 04:53:27
adarshmacl@gmail.com from India  
rating
Very helpfulllllllllll


Depending on the web browser, the document itself will load right away and then multiple connections to your web server will fetch images and javascript include files. The web page may be rendered before the javascript is loaded.

is Correct
2007-07-20, 13:16:04
anonymous from United States  
More importantly, it allows you to share code across pages. If you have a few functions that you're going to use on every page, putting them in an include file means you only have to edit them in one place, and the client only has to load them once. So, if they visit more than one page on your site, the second page loads faster than the first.

The same is true of CSS.
2008-10-08, 09:18:11
anonymous  



Keywords:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: