See Loading scripts (old) for old information.
In short. If you are just loading scripts from a central file, use include(). If you are loading scripts at the top of different files use include.once() so that a script only gets loaded once. If you want the value of the last expression in that file use globalExec(). Or if you want that executed in the scope you are currently in use exec(). Be warned though that exec() may make use of eval and isn't as fast as the rest of the methods.
Full descriptions
- exec(script, [encoding])
- Useful for executing scripts within the current scope.
- Runs script in current scope. Returns the value of the last expression in the script.
- globalExec(script, [encoding])
- Useful for executing scripts and getting the result from them (like a file entirely comprised of E4X or a JSON file you want to allow script execution in).
- Runs script in global scope. Returns the value of the last expression in the script.
- include(script, [encoding])
- Useful for general inclusion of other scripts.
- Runs script in global scope. Returns true.
- include.once(script, [encoding])
- Useful for inclusion of other scripts when you may have the same include in multiple files, such as declaring dependencies as includes at the top of files.
- Same as include() but does not load the script if loaded before by include or include.once.
- include.ifExists(script, [encoding])
- Useful for including batches of scripts which aren't necessary to the program such as init scripts.
- Same as include() but returns false instead of true if the script does not exist.