Lazy Loading
Lazy loading of modules is the concept of only loading a module when it is explicitly required. Thus helping to improve website performance.
CMSMS allows the programmer to choose if a module should be lazy loaded for frontend and/or admin requests, and implements various caching techniques to aide in that. i.e: The admin navigation is cached for each user so that once the cache is built, the module may not be loaded for subsequent requests, until visiting the module's admin panel or utilizing other functionality implemented by the module.
However, there are some disadvantages to lazy loading, and some times where lazy loading must be explicitly disabled depending on the functionality of the module. Therefore it is important to at all time keep the module class as simple and as small as possible, and to relegate functionality as much as possible to other classes, and to action and event files.
When you can't use Lazy Loading
Frontend | Admin | |
---|---|---|
The module uses a tag alias1 | Register in install | N/A |
The module uses Pretty URL's2 | Register in install | N/A |
The module creates content types3 | No | No |
The module handles hooks | No | No |
Enabling or Disabling Lazy Loading
There are two methods in the CMSModule class that you must override in your module to enable or disable lazy loading: LazyLoadFrontend()
and LazyLoadAdmin()
. Both if these modules must return a boolean.
public function LazyLoadFrontend() { return true; }
Note: Because flags that tell CMSMS whether or not to load your module for each request are stored in the database, you must bump the version number of your module each time you change these methods.