CdnSupport module preview
“A content delivery network or content distribution network (CDN) is a system of computers networked together across the Internet that cooperate transparently to deliver content most often for the purpose of improving performance, scalability, and cost efficiency, to end users.” - Wikipedia
This is the CdnSupport module used in Mats & Peters presentation on the EPiServer Day on client-side performance. It is an unsupported module that you can download in binary form and try yourself, it will probably end up either as an open open-source module or as part of the product.
Offloading the burden of delivering static files from the web server is one way of scaling out your system, its better to have one system optimized for delivering static content and another optimized for delivering dynamic content, right ? Another reason is that you want your static content cached closer to the user, hence making your site more responsive.
How does it work ?
It rewrites URL’s from:
The “mydomain“ is your CDN and the strange characters in the middle is the changed date of the file in hexadecimal form.
If you are using a CDN your file may end up cached on a server across the globe and it won’t get evicted until it expires (for example 1 day). That is why the module injects the changed date into the URL, as soon as you change the file the URL changes and you get fresh copies of the file. Simple but effective, thanks Tom Stenius for the idea.
Remember that most cache servers and CDN’s require you to set valid expiration date on your files to actually cache anything, this module will not do that for you.
Do I need a CDN to test this module ?
No, you can point it back to the origin site if you like to test it (or just utilize the fact that a browser limits the number of ports per domain name). You can also use a caching server like Varnish.
What CDN’s are supported ?
This module has been tested with EdgeCast and Akamai but should work with most of them like Limelight Networks etc. There are many others but some such as CacheFly only supports files stored on their servers so make sure they support “customer origin” if you are using this module.
Links that it cannot get the changed date for are ignored. It also does a security check on VPP-files to make sure Everyone has Read access since the CDN will not be able to fetch it otherwise (they normally don’t forward cookies etc). If you are using files protected by some other mechanism this module will not work correctly.
URL’s are rewritten using the existing infrastructure of events in EPiServer CMS. A custom cache is used to speed up the changed-date lookup since there can be large amounts of resources per page that need to be parsed. The cache stores lookups for 10 minutes and up to 10,000 entries using a LFU-scheme for eviction.
You can add “?cdn=off” to the URL to disable rewriting if you a member the Administrators group. You can also add “?cdn-microcache=debug” to see statistics on the custom cache.
This module will not rewrite any URL’s originating from a preview in edit mode or when you supply a version of a page.
There are three known areas that need more work:
- Need more performance testing on how this module affects the site, I've only done performance testing in unit tests and on Labs.
- There is no way to have different settings for different folders with static files, you can only have different settings for different templates by using the location-element.
- The internal cache will not expire instantly in load balanced scenarios (the changed date in the URL, not the actual file which get updated).
1. Add config-section (configuration->configSections):
1: <section name="cdnSupport"
2: type="EPiServer.CdnSupport.CdnSupportSection, EPiServer.CdnSupport"
2. Add the actual config:
1: <cdnSupport enabled="true"
4: extensions="*" />
3. Drop the DLL in bin-folder
4. Under Modules add this after the UrlRewriteModule:
1: <add name="CdnSupport"
2: type="EPiServer.CdnSupport.CdnModule, EPiServer.CdnSupport"