ajile: Learn: FAQ: Load vs. Import



Back to Documentation


Q1: What's the difference between Load and Import?

A1-General: The Load and Import directives are both designed to allow scripts to programmatically define their dependencies.

A1-Part 1: The purpose of the Load directive is to provide developers with a means to programmatically load other arbitrarily named scripts. The Load directive should be used when you simply want to load an external script file from a known location.

A1-Part 2: The Import directive serves two purposes. The first being to provide developers with a means to programmatically load " namespace'd" scripts. Namespace'd means that a script has been named in a manner, or stored in a directory structure that reflects the namespace it programmatically defines. Ajile allows developers to package namespace'd scripts by:

   1. Using a directory structure that reflects the namespace. For example:
      /com/iskitz/ajile.js indicates that this script defines the namespace
      com.iskitz and the type/object ajile within it.

   2. Naming the script in a manner that reflects the namespace. For example:
      com.iskitz.ajile.js indicates that this script defines the namespace
      com.iskitz and the type/object ajile within it.
     
The two approaches are made available to accommodate developers' different organizational styles, either one can be used; the choice is the developer's. When the Import directive is used without its optional url and packaging style parameters it automatically determines the script's packaging style and location based on those of previously loaded scripts with a common namespace, or if no others have been loaded, then the location and packaging style of Ajile itself.

A1-Part 3: The second purpose of the Import directive is to provide "short-name" access to types/objects defined within loaded scripts. After the namespace'd script is loaded its short-name is mapped to its fully-qualified name. For example:

Import ("com.iskitz.examples.Site");
instructs Ajile to load com.iskitz.examples.Site.js and map its contained com.iskitz.examples.Site object to the short-name Site.

Back to Documentation