RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


A Server-Side Assist for Loading Client-Side JavaScript Code

JavaScript lacks a function for loading and executing a library file while it's executing a main program file. Implementing an include directive on the server side is a simple technique for getting around this limitation.

f you're at all involved with Web development, you know about AJAX (Asynchronous JavaScript and XML). And you probably noticed the astonishing proliferation of AJAX frameworks, which provide a unified set of libraries for writing AJAX applications more easily.

One of the reasons frameworks are so important is that JavaScript isn't quite ready for programming in the large. Don't get me wrong—the language is beautifully designed, but some of the subtleties of in-browser programming, to say nothing of cross-browser portability issues, can make JavaScript development something less than smooth. One example is its poor support for the include statement, which enables one file to draw in the contents of another—usually a file containing a useful library. Just about every language has a mechanism for this, and various Web technologies have a number of different ways of providing include functionality.

The AJAX frameworks solve these problems to one degree or another. Each one attempts to hide platform incompatibilities behind abstractions and adapt some of the metaphors of traditional programming language environments into the browser. However, the browser may not be the proper place to deal with the include limitation. This 10-Minute Solution suggests that you implement include on the server side (using a simple CGI script) rather than trying to get browsers to do it.

JavaScript doesn't have a function that loads and executes a library file in the middle of executing a main program file. How do I implement this function in JavaScript when it doesn't have an include directive?

Implement include on the server side using a simple CGI script.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date