In CQ or AEM, most of the pages remain static. Hence, caching of the pages is very useful with dispatchers or any other available AEM plugins/connectors. Imagine a scenario where homepage of news agency must show the hot news which is different for different regions, however, because of caching it is displaying the same news in all the regions. Strange! To rescue from these, live scenarios, the application may require certain elements/components of the page to be dynamically included. In AEM, Sling Dynamic Include (SDI) provides this functionality.
Let’s elaborate SDI integration with AEM 6.4, Dynamic Include 3.0.0 and Dispatcher 2.4.
Please note that Step 1 and Step 2 need to be performed on publish instance.
Install Sling Dynamic Include Bundle using the following steps:
Please find below the brief description of each OSGI config used above:
enabled – set it to true to enable SDI.
path – SDI configuration will be enabled only for this path.
resource-types – which components should be replaced with tags
ApacheSSI – Apache Server Side Includes
Apache HTTP Server is set up as a caching proxy in front of the AEM. This means that the include will be done by the http server and not by the sling engine.
ESI – Edge Site Includes
Edge Site Includes can be used as an alternative to SSI, it is evaluated by CDN. ESI has to have some proxy that is able to process its tags and often made available as part of CDN.
Using JSI will replace dynamic components with ajax tags, so they are loaded by the browser. If included component has some JS code, it may not work properly, as it won’t be initialized immediately after a page is loaded.
Add comment – adds debug comment: <!– SDI include (path: %s, resourceType: %s) –> to every replaced component.
Filter selector – selector added to HTTP request for particular component and is used to get actual content.
TTL – time to live in seconds, set for rendered component. This property is supported for dispatcher version 4.1.11+
Required header – SDI will be enabled only if the configured header is present in the request. By default it’s Server-Agent=Communique-Dispatcher header, added by the AEM dispatcher. You may enter just the header name only or the name and the value split with =.
Ignore URL params – SDI normally skips requests containing any GET parameters. This option allows to set a list of parameters that should be ignored.
Include path rewriting — enable rewriting link (according to sling mappings) that is used for dynamic content including.
After completion of Step 1 and Step 2 on publishing instance, Dispatcher configurations need to be updated as explained below:
1. Include(If already present, make sure uncommented) the mod_include module in Apache Web server’s httpd.conf file:
LoadModule include_module modules/mod_include.so
2. Update virtual host configuration file
a. Find the following lines in the dispatcher.conf file
modify as below
b. Add Includes to Options directive:
Options FollowSymLinks Includes
3. Update the httpd.conf to enable SDI.
a. Add “Includes” to Options directive to enable SSI includes used by Sling Dynamic Include
b. Specify what file types are to be processed by Includes filter.
Options Indexes FollowSymLinks Includes
AddOutputFilterByType INCLUDES text/plain text/html
4. Update rules.any or dispatcher.any depending where the cache rules are defined for the publish instance.
Make sure the selector ‘nocache’ used here is same as defined in OSGI config (include-filter.config.selector = ‘nocache’) explained in Step 2.
5. Restart the server using any of the below commands:
sudo apachectl restart ORsudo service httpd restart
After setting up the SDI, it’s time to verify the changes. Follow the below steps:
Right click and open the page source on the webpage where the component is dynamically included.
In the page source, search for SDI includes tag.
A component configured for SDI will be replaced with SDI tags as shown below: