KalioCommerce Blog Background Image

KalioCommerce Blog

Optimize Cache Timing for CDN's

Best Practices Cache CDN 700_400.jpg

Utilizing a Content Delivery Network (CDN) is not optional anymore and is a required tool in your website performance toolbox.  This blog post will explore some of the important strategic decisions for a merchant to consider to optimize your use of a CDN.

CDN Caching Basics

Most eCommerce sites today utilize a Content Delivery Network (CDN) to optimize site speed and performance.  Even though most sites are using a CDN, typically there are opportunities to optimize and take full advantage of the service.   Any file retrieved from a CDN, whether a page or individual file, will give you the fastest possible performance for that content because the content is being delivered from distributed edge servers that are closer to your customers based on their geographic location.  Retrieving content from these point-of-presence servers will provide the best performance results.

Secure vs Non–Secure Content

Everyone wants their information to be protected and secure when shopping online and Google is pushing us all to move from HTTP to HTTPS - Non-Secure Content to Secure Content sites.  Not so long ago, the price to cache secure content in a CDN was steep but recently the cost has come down significantly making this transition affordable.  Given that all of us want to shop on secure sites and the push from Google to move to Secure Content Sites, make sure the CDN provider you choose supports the caching and delivery of secure content.

What can you cache in a CDN?

As the name suggests, it’s all about the content that populates your web pages.  The page files that are loaded, like images, CSS and Java Script files are prime caching candidates.  In addition, full page caching is also an option putting your HTML, ASPX or PHP generated pages on the edge to enable pages to be cached and served from those point-of-presence servers.  Note, you will need to identify shopper specific content on these pages and deploy a solution to populate those sections of the page after the initial page is downloaded from the CDN.  Keep in mind that regardless of the file type, you must set the time (it’s expiration date) the file will remain cached.  As a rule, the longer you can set the expiration date the better performance you will have.  As an example, setting a 30-day expiration date for CDN files will provide better performance for repeat visitors.  Your shopper’s browser will cache content based on file expiration dates from the origin.  Setting a 30 day or longer expiration date will reduce the number of files that must be re-fetched for each page load resulting in a faster shopping experience for the shopper.

Caching Files

When thinking about caching files, you might want to think in terms of files that change rarely, files that change occasionally and content that is visitor specific.

For files that change occasionally, using a versioning strategy is key.  Set a long cache expiration at 30 days or more if possible.  The most popular strategy for automatically updating your CDN with new content is to append a query string parameter to the URL of the file to enable instantaneous changes i.e. JavaScript, CSS files or images. This strategy works because the CDN caches based on the uniqueness of URL’s. 

For example: www.myecommercesite.com/javascript/jquery.js?v=102 vs. www.myecommercesite.com/javascript/jquery.js?v=103 or www.myecommercesite.com/javascript/jquery.jsv=104.

This allows you to trigger changes when you need them or otherwise benefiting from a long expiration date. 

The solution for rarely changed files is similar to files that change occasionally.  Files that rarely change like images, should have long expiration dates and be set for 30 days or more.  Typically, images files have unique names so a versioning strategy is not necessary.  However, using a versioning strategy certainly can be used for this content for those occasional times you want to replace an image file.  For these types of files, it’s best not to use the same file name like Promo.jpg.  It’s better to have unique names like Labor_Day_Promo.jpg and Halloween_Promo.jpg.  If you must use the same names, using an expiration date versioning strategy is required.

Visitor Specific Content will be the most complex area to handle.  Content such as Personalized Content, Shopping Cart, Promotional and Customer Specific Pricing are all things that need special care.  Depending on the CDN provider, different tools are available to support always retrieving these visitor specific content pages directly from the origin.  Ask your eCommerce provider to utilize AJAX to load all such content after the static page is delivered from the CDN.  This strategy will provide the best possible performance.

Using a versioning strategy for images, JavaScript, CSS files and visitor specific content enables you to have a long cache timeout with no manual purging of the files required.  New asset files will automatically be pulled based on the versioning dates you set.  If your eCommerce platform does not support file versioning, that is a capability you definitely want to identify as a high priority when you replace it.

Deliver an Exceptional Customer Experience. Get the eBook.

Deliver an Exceptional Customer Experience. Get the eBook.

Subscribe to Email Updates

Recent Posts