April 1, 2020
Estimated Post Reading Time ~

Sample httpd.conf Configuration to Enable Cache-Control HTTP Response Headers for CQ Dispatcher

There are a number of CQ-hosted websites out there that make little or no effort to leverage proxy and browser caching by setting appropriate HTTP Response Header values. As a result, you are unnecessarily paying your CDN (Content Delivery Network) provider extra dollars because user browsers keep requesting pages, images, Javascript and CSS files for every page request in a session when they easily could be caching them locally.

Akamai’s Mark Nottingham has an excellent tutorial on this subject here.

Given below is a sample adapted from Charles Torvalds' AskApache (make changes as you wish/require):

Enable the mod_expires and mod_headers modules by un-commenting the following lines in httpd.conf (if needed):

LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so

KeepAlive On

ExpiresActive On
ExpiresDefault “access plus 1 day”
ExpiresByType text/html M86400
FileETag INode MTime Size

Header append Cache-Control “public”
Header add X-ServiceProvider “Adobe Managed Services”

# Set up caching on media files for 1 week
<FilesMatch “.(gif|jpg|jpeg|png|swf)$”>
ExpiresDefault A604800
FileETag INode MTime Size
</FilesMatch>

# Set up 2.5 Hour caching on commonly updated files
<FilesMatch “.(xml|txt|js|css)$”>
ExpiresDefault A9200
FileETag INode MTime Size
Header append Cache-Control “proxy-revalidate”
</FilesMatch>

# Force no caching for dynamic files (not CQ-related but…)
<FilesMatch “.(php|asp)$”>
ExpiresActive Off
Header set Cache-Control “private, no-cache, no-store, proxy-revalidate, no-transform”
</FilesMatch>

Here’s what the HTTP Response Headers will look like when the above configuration is in place (Firefox 27.0 Web Console’s Network tab):



Please note that setting the following in your CQ .jsp files only affects the caching behavior of CQ Dispatcher.

response.setHeader(“Dispatcher”,“no-cache”);


Reference: https://cloud-ops.tumblr.com/post/76755025204/sample-httpdconf-configuration-to-enable


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.