Sling Dynamic Include
Sling Dynamic Include is a feature provided by the Apache
Sling framework, which is the underlying web framework of AEM. SDI allows for
dynamic inclusion of content from external resources or other AEM pages within
AEM pages at runtime.
Here's a brief explanation of Sling Dynamic Include and a
comparison with other similar technologies:
Sling Dynamic Include (SDI):
·
Sling Dynamic Include allows you to include
content fragments dynamically within AEM pages.
·
It enables the inclusion of content from
different sources such as external URLs, other AEM pages, or even specific
components.
·
SDI is often used for including dynamic content
like advertisements, promotional banners, or content from external systems.
Server-Side Includes (SSI):
·
Server-Side Includes (SSI) are directives that
are placed in HTML pages to instruct the server to include external files or
execute scripts before serving the page to the client.
·
SSI is typically processed by the web server (e.g.,
Apache HTTP Server) before the page is sent to the client's browser.
·
While SSI and SDI serve similar purposes of
including dynamic content, SDI is specific to AEM and integrates within its
framework, whereas SSI is more commonly used in general web server
configurations.
Server-Side Rendering (SSR):
·
Server-Side Rendering (SSR) involves generating
the HTML for a web page on the server and sending the fully rendered page to
the client's browser.
·
SSR is commonly used in traditional web
applications to improve initial page load performance and SEO.
·
Unlike SSR, SDI doesn't render the entire page
on the server side but allows for the inclusion of specific content
dynamically.
Configuring SDI on AEM
1.
Download the Sling Dynamic Include bundle,
search for “Dynamic Include” and download the Bundle.
2.
Install the bundle in the Apache Felix bundles
console of AEM Publish instance.
3.
Configure Sling Dynamic Include via the OSGi
Configuration Factory at http://<host>:<port>/system/console/configMgr/org.apache.sling.dynamicinclude.Configuration
4.
Once this configuration is enabled, you can load
the page where the component is configured and if you inspect the source code,
you can see the component div like this –
In the above screenshot, the code part i.e.
<!–#include virtual='</path/to/resource/component.nocache.html’ –> is
the part where the actual code will be replaced once the dispatcher is enabled
with Sling dynamic include settings.
Configuring SDI on Dispatcher
the minimal configuration necessary to use Sling Dynamic
Include on Dispatcher are as follows,
1.
Enable mod_include in httpd.conf
LoadModule include_module
libexec/apache2/mod_include.so
2.
Update the vhost file to respect include
directives.
<VirtualHost *:80>
...
<Directory /Library/WebServer/docroot/publish>
...
# Add Includes to enable SSI Includes used by Sling Dynamic Include
Options FollowSymLinks Includes
# Required to have dispatcher-handler process includes
ModMimeUsePathInfo On
# Set includes to process .html files
AddOutputFilter INCLUDES .html
...
</Directory>
...
</VirtualHost>
3.
Update the dispatcher.any configuration file to
support (1) nocache selectors and (2) enable TTL support.
/rules {
...
/0009 {
/glob "*.nocache.html*"
/type "deny"
}
}
/cache {
...
/enableTTL "1"
}
Benefits of Sling Dynamic Include
·
Allows to serve highly dynamic content at the
same time, allows to cache a fragment of the page using the “.html” extension
·
It can make your pages more modular and easier
to maintain.
·
It can be used to include dynamic content that
is generated by a script.
Limitations of Sling Dynamic Include
·
It can be complex to configure.
·
It can only be used with Sling-based
applications.
·
It can introduce security vulnerabilities if not
used properly.
Conclusion : Sling Dynamic Include is a powerful feature
that can be used to improve the performance and maintainability of your Adobe
Experience Manager pages.