logo To Foot
© J R Stockton, ≥ 2010-02-23

JavaScript Include Files.

No-Frame * Framed Index * Frame This
Links within this site :-

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

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 include2.js (used only in JavaScript Tests, and below) as a trivial example (the comments are not necessary) :-

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.

Type Omission

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 include0.js.

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

A test variable is declared in include2.js.

General JavaScript date routines are coded in include3.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 "Code Display on This Site" in Index and Introduction, and page Code Boxes. For the coding of the double-bordered boxes, see ShoFFF() etc. under "Code Display" in the include1.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 :-

Contents of my file include0.js

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

Contents of my file include1.js

Contents of my file include2.js

Contents of my file include3.js

Contents of my file include4.js

Contents of my file rndg-inc.js

Contents of my file estr-inc.js

Contents of my file zell-inc.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
Home Page
Mail: no HTML
© Dr J R Stockton, near London, UK.
All Rights Reserved.
These pages are tested mainly with Firefox 3.0 and W3's Tidy.
This site, http://www.merlyn.demon.co.uk/, is maintained by me.
Head.