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:
Configuration required (on every VPP you whish to enable it for):
1: <location path="Global">
2: <staticFile expirationTime="1.0:0:0"/>
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"/>
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.