Category: dispatcher

Cache static object for better performance AEM 5.6.1

Several contents i.e. CSS, image and icons don’t get changes frequently, therefore the system should be configured so that requested objects does not get expired in client browser and reduce unnecessary HTTP traffic.

This unloads the traffic request from server also improves user experience response time for page and any HTTP request as browser stores the objects in browser cache based on expiration date for the path.

Any HTTP request has header information and HTTP protocol allow browser to cache based on that information.

Apache configuration changes

Uncomment this in httpd.conf.

LoadModule expires_module modules/mod_expires.so

and load this changes where for the content path or any directory/folder that you want caching.

<Location /libs>
ExpiresActive On
ExpiresByType text/css “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 hour”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 hour”
</Location>

 

<Location /etc/designs>
ExpiresActive On
ExpiresByType image/gif “access plus 1 hour”
ExpiresByType image/png “access plus 1 hour”
ExpiresByType image/svg “access plus 1 hour”
ExpiresByType image/jpeg “access plus 1 hour”
ExpiresByType image/jpg “access plus 1 hour”
ExpiresByType application/x-javascript “access plus 1 hour”
ExpiresByType text/css “access plus 1 hour”
</Location>

 

How to ensure it is effective?

If expiry is not active

We will see such log in access.log of apache for any image objects for each request.
127.0.0.1 – – [11/Apr/2014:16:02:35 -0500] “GET /content/dam/IMAGES/Brand%20Assets/hero-home-1.jpg HTTP/1.1” 200 496832That means image file of size 496832 bytes are being downloaded on each request. 200 is http successful status.

If expiry is active, ideally we should see logs like this
127.0.0.1 – – [11/Apr/2014:16:53:32 -0500] “GET /content/dam/IMAGES/Brand%20Assets/hero-home-1.jpg HTTP/1.1” 304 –

 

That means 304 indicates that browser has cached that image and server has not got any new version so apache is not going to send back to browser a new copy and reducing http traffic.

Run Load test and check logs

 

Advertisement