PreImport allows you to import a module before the next page request.

The advantage of this is that modules that take a long time to load will all ready be loaded when a user requests a page. The module still needs to be explicitly imported, but the loading and initialization of the module will have already been completed. This can lead to increased peformance when importing heavy modules that take a long time to load and initialize.

There are three things to note about using the PreImport directive:

  1. If the pre-imported module is updated, the effects will not be seen until after the next request, since the module has already been pre-imported.
  2. The module(s) must be within default python import path (aka sys.path).
  3. The module is not persistent; that is, each request sees a newly loaded and initialized module. Modules can be persisted by using a plugin or custom tag.