logo To Foot
© J R Stockton, ≥ 2012-07-29

JavaScript Include Files.

Links within this site :-

See "About This JavaScript Site" in JavaScript Index and Introduction.

There is a ZIPped snapshot including JavaScript include files and HTML CSS files (38kB+), taken on or after 2013-01-11; unZIP it in an empty directory.

As with other pages, the date of the page is independent of the dates of the include files shown.

Overview of Include Files

Where code is common to more than one Web page, it is effective to put it into one or more "include" files, so that only one copy needs to be maintained and transmitted.

With an invocation such as

An include file can contain functions, declarations, and other statements; but not overt HTML. Here is a representation of my complete inc-test.js (used only in JavaScript Tests , and subsequently included dynamically) as a trivial example (the comments are not necessary) :-

function CaptionTest() {
  //     JAVASCRIPT INCLUDE FILE - (c) J R Stockton  >= 2012-05-13
  //             inc-test.js
  }

var TestCounter = 1 ;

function ink_test() {
  return "Hello from inc-test.js" } // Simplified here

// end.

Often, the include statements will be placed at or near the top of a Web page, in the HEAD or BODY section.

Extension

Extension .js is commonly used, but has the disadvantage when used in the URL of a link that the file may then be treated as a Windows executable.

File Existence

If a required include file is missing, code needing it will fail, perhaps confusingly. After invoking, I test by code like :-

In fact, I check variables defined at each end of the file, since it is possible for a file to be only partially up/down-loaded.

Omission of Type

In a <script ... > part, if the type attribute is not set, the previous value is used; the default is JavaScript. The only other type I actually know much of is VBScript.

Defer

I have read that adding defer="defer" in the script tag allows page parsing to continue, since the included file code does not invoke any writes.

Dynamic Inclusion

Code to select an include file can be written into a page while it is loading, but the contents must not be used until the file has loaded - or so it seems.

More elegantly, see Bart Van der Donck in news:c.l.j 2008-03-25.

My Include Files

Disused JavaScript routines are coded in inc-aged.js.

General JavaScript routines are coded in inc-cmmn.js, including the routines used to display in boxes with coloured borders.

A test variable is declared in inc-test.js.

General JavaScript date routines are coded in inc-date.js, and widely used in my pages.

Other include files are specific to my Rounding, Zeller, and other Easter pages.

The include files may also define a few variables.

My code can be used as code (where the boxes do not suffice, try View Source, in the page or on a browser menu), but should not be re-published.

Display of Code on This Page

Display of code, and parts of this page, require JavaScript.

Microsoft Internet Explorer (4-7, +?) and Google Chrome display functions and methods as written, in the original layout and complete with comment. If your browser does not (e.g. Firefox, Opera, Safari), you should resort to View Source or an independent viewer.

Read "Function Display on This Site" in Index and Introduction, and page Code Boxes. For the coding of the double-bordered boxes, see ShoFFF() etc. under "Function Display" in the inc-cmmn.js section of this page.

Simple Functions are shown in full. Added Methods may be shown as function anonymous with their names following in comment.

Some supplementary Methods may be conditionally defined; if you already have them, [native code] will be shown.

Functions Caption. contain identifying comment, and are functions merely in order that the comment can be shown.

Limits

Some routines, particularly date ones, have limited range :-

TEST Script Element verbatim display

Script number     Max about 26

Contents of my file inc-aged.js

I no longer use this include file or these functions elsewhere.

Contents of my file inc-cmmn.js

Contents of my file inc-test.js

Contents of my file inc-date.js

Contents of my file inc-estr.js

Contents of my file inc-grfx.js

Contents of my file inc-modt.js

Date mouseover popup.

Contents of my file inc-prop.js

Contents of my file inc-rndg.js

Contents of my file inc-zell.js

For The Calendrical Works of Rektor Chr. Zeller : The Day-of-Week and Easter and associated pages.

JavaScript Index and Introduction
JavaScript Date and Time
© Dr J R Stockton, near London, UK.
All Rights Reserved.
These pages are tested mainly with Firefox and W3's Tidy.
This site, , is maintained by me.
Head.