DelphiFAQ Home Search:
General :: Web publishing :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Advantages of keeping Javascript in include files


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


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.

Generated 12:02:26 on Oct 13, 2019