Take the community feedback survey now.

Per Bjurström
May 19, 2009
  17256
(4 votes)

CdnSupport module preview 2

Please read this article about Preview 1 before you continue reading, it covers the basics.

I’ve added another feature to the CDN module to support “far future Expires-header”. As described in Preview 1 you need to set an Expires header on your files for the CDN to cache your files, this header controls how long the CDN (as well as the browser) is allowed to keep the file in the cache. The longer the better, but then changes you make to existing files may never get updated.

You should still use that but since this module supports injecting changed date information into the URL we can enhance it with the “far future” pattern as described by Best Practices for Speeding Up Your Web Site. This feature is enabled by changing the StaticFileHandler in EPiServer CMS to a slightly modified version, this modified handler discovers CDN-requests and changes the Expires-header to the far future (1 year, which is the maximum in ASP.NET). Whenever a “normal” request comes in it just passes the request to the built-in handler in EPiServer CMS. Best of both worlds.

This feature is optional, you don’t have to use it since you could set the expires to a far future on the built-in StaticFileHandler but that will affect all requests (even those without the changed date in the URL). By the way, have a look at System.Web.HttpCachePolicy.SetExpires in Reflector. You are not allowed to increase the expires, only decrease it. Nice one. That is why this feature is implemented as an StaticFileHandler instead of just listening to events.

Snapshot from Firebug:

image

 

Configuration required (on every VPP you whish to enable it for):

   1: <location path="Global">
   2:     <staticFile expirationTime="1.0:0:0"/>
   3:     <system.webServer>
   4:         <handlers>
   5:             <add name="webresources" path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader"/>
   6:             <add name="wildcard" path="*" verb="*" type="EPiServer.CdnSupport.CdnStaticFileHandler, EPiServer.CdnSupport"/>
   7:         </handlers>
   8:     </system.webServer>
   9: </location>

 

This version also fixes a bug that only surfaced if you were running an Enterprise-configuration, basically the site did not start.

Remember that the StaticFileHandler only delivers files located in EPiServer, not CSS-files etc (at least on IIS7). The recommended pattern for external files is that you version your resources on the site yourself. Again, see the Best Practices for Speeding Up Your Web Site.

Download the package here.

May 19, 2009

Comments

Sep 21, 2010 10:32 AM

Per, I could kiss you! Or at least almost :)
On the project that I'm currently working on we've been playing around with the CDN-module to improve the sites ranking in YSlow (which compares a site against the above mentioned performance rules) and this improvement just made my day! Thank you!
/ Joel Abrahamsson (joel.abrahamsson@nansen.se)

per
per Sep 21, 2010 10:32 AM

Wow, that is timing! Let me know if you have any feedback or suggestions.

Sep 21, 2010 10:32 AM

Per, got any advice on how to make the module handle javascript files added with a scriptmanager? Currently it rewrites all paths and adds the date information to the url except two js-files that are referenced through the scriptmanager.
/ Joel Abrahamsson (joel.abrahamsson@nansen.se)

per
per Sep 21, 2010 10:32 AM

I tried to implement support for those ScriptResource/WebResource files but did not get it to work, so I gave up on that approach.

I would look into customizing ScriptManager instead, let me know if you find anything.

Sep 21, 2010 10:32 AM

I see, but in this case it's for js-files and not scriptresources/webresources, but it's quite possible that I'm missing something in my configuration. Will look into that.

A bit more feedback/issues:

* It doesn't seem to rewrite relative urls in html-comments, like

* It seems to add expirationheaders to the above css-file even though the URL is not rewritten and I'm using the CdnStaticFileHandler. My configuration for the styles location looks like this:









/ Joel Abrahamsson (joel.abrahamsson@nansen.se)

per
per Sep 21, 2010 10:32 AM

You should not get the 1-year expiration header on files that are not rewritten, in your case you should get 3 days since that is what you have specified as default. Basically the CdnStaticFileHandler just passed the request to the built-in version if its not a CDN request.

Sep 21, 2010 10:32 AM

Ahh, brilliant!
/ Joel Abrahamsson (joel.abrahamsson@nansen.se)

Wacdany R.
Wacdany R. Jul 18, 2013 05:09 AM

Hello Per,

Thank you so much for this collaboration! It really looks promising.
We are looking to implement a CDN support for Akamai on EpiServer 7 and since this post dates for 2009 I just wonder if you have done any compatibility test for this module on EpiServer7 or if there is any other recommendations you might have regarding Akamai CDN + EpiServer7?

Best Regards,
- Wacdany R.

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP - Introducing the beta of Opti Graph Extensions add-on

Introducing Opti Graph Extensions: Enhanced Search Management for Optimizely CMS I am excited to announce the beta release of **Opti Graph...

Graham Carr | Sep 15, 2025

Content modeling for beginners

  Introduction Learning by Doing – Optimizely Build Series  is a YouTube series where I am building  a fictional  website called  TasteTrail , food...

Ratish | Sep 14, 2025 |

A day in the life of an Optimizely OMVP - Enhancing Search Relevance with Optimizely Graph: Synonyms and Pinned Results

When building search experiences for modern digital platforms, relevance is everything. Users expect search to understand their intent, even when...

Graham Carr | Sep 14, 2025

Optimizely CMS and HTML validation message: Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.

When using the W3C Markup Validation Service, some annoying information messages pop up because Optimizely CMS adds the trailing slash to...

Tomas Hensrud Gulla | Sep 14, 2025 |

Turbocharge your strings - a case of display channels

When doing a routine performance test, during a CMS 12 upgrade, I was able to achieve 95% performance improvement. Let's look at SearchValues with ...

Stefan Holm Olsen | Sep 14, 2025 |

Opal Core Concepts

Before you dive into the code, it's crucial to understand the foundational ideas that make Opal tick. Core concepts are consistent across all its...

K Khan | Sep 13, 2025