SaaS CMS has officially launched! Learn more now.

Caching both static and dynamic content in AWS CloudFront


We are hosting EPiServer on AWS platform. We want to leverage CloudFront CDN. We have run into several issues that has made this a little bit challenging.

1. Our initial attempt was to store the images in S3 and use URL rewriting to insert the CDN endpoint in the path so our client browsers directly download content from CDN. This was working however the URL's were not SEO friendly. So we had to given up on serving content directly out of S3 bucket.

2. Our 2nd attempt to leverage CDN was to put our entire website behind AWS Cloud front. Even though our images are still stored in S3 our HTTP requests go from Cloudfront to AWS ELB to EC2 instances. Which fetch content from S3, provide friendly names for images. This is not as nice as option 1 because web servers have to perform extra processing. I am running into an issue where EPiServer is marking the content with    cache-control: private which prevents caching of dynamic content.

I found a similar issue  in this forum

the solution suggested requires over riding the base page:

var cache = System.Web.HttpContext.Current.Response.Cache;

We have these settings in our web.config but all content is still marked as private.

httpCacheability="Public" uiEditorCssPaths="" urlRebaseKind="ToRootRelative"
pageUseBrowserLanguagePreferences="false" uiShowGlobalizationUserInterface="true"
uiMaxVersions="20" pageValidateTemplate="false" uiUrl="~/adminui/CMS/" />

We also added:

It will be helpful to get your guidance on 1 and 2. Is there any way to get friendly names and still serve images/css/js directly out of S3. This is our preferred approach.

If the answer is no than we need to know the settings in web.config that should set the cachebility to Public instead of private.


Feb 18, 2016 17:39

CMS automatically set Cache Control to public for content media when you are not logged in, if you are logged in it will be private, see this section for configuration:

You could also use the open-source CDN module to enable aggresive caching with semi-friendly URLs to make maximum use of your CDN, I would think that is your best bet, see:

Feb 19, 2016 8:58

Is it possible to override the default behavior so we can cache images/css/js for the users that are logged in?

In other words can we set the cache-control to public for media assets for logged in users?


Feb 19, 2016 18:10

Yes, just change configuration per the link above. It defaults to the behaviour I mentioned.

Feb 20, 2016 10:19
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.