CDN/sub-domain, resources, and versioning

I’m hoping to investigate/implement a CDN (initially just via a sub-domain, though moving over to CDN in time) and am having a mare finding resources that talk about handling of versions of files on that sub-domain.

Most places I’ve worked previously have implemented caching of resources (images, javascript, css, etc.) and when wanting to change an image, have gone through the painful process of just changing the filename of the image, and changing the reference to it in the source code (so that customers see the new, not the cached image).

What I want to achieve

what I'd like is: resources.domain.com

with sub-folders such as:

  • scripts/
  • images/
  • css/
  • etc.

not a problem, and will help with the yslow/page speed scores (assuming cookieless domain etc.)

But versioning of assets is something I want to resolve.

E.g.

resources.domain.com/images/promo_banner1.jpg

I'd probably have to cache and expire perhaps every 10-15 days.

Assuming we have something key come in as a business request, and we need to change it, I want to be able to override that. From what I understand, I could append a querystring (?1.1) to it to force browsers to see it as a different resource.

I know I can do this in MVC (or indeed ASP.NET) by creating a 'CompanyResource' html helper that will lookup against perhaps a resource file or something similar to see if we have a new version, and if so, append the version number as a querystring element, but there has to be a better way?

So, what has the community come up with?

  • how best to deal with resources in a sub domain (assume I've read all of the yslow/google backup docs around this)
  • what have folks come up with to handle versioning of assets (to minimise overall code changes when something updates) - code based helper methods to deliver assets based upon some rules?

Hopefully I haven't waffled too much.

Thanks for any and all help :)

Cheers, Terry

Comments


  • Mole

    just noticed this one hadn't been answered - we resovled our problem with Html helpers under ASP.NET MVC using the following.

    In web.config we stored the 'resources_url' (in this case resources.mycompany.co.uk), and called the following:

    <%= Html.MyCompanyResourceScript("~/scripts/jquery-1.4.2.min.js") %>
    

    Which translated to an Html helper:

    public static string MycompanyResourceScript(this HtmlHelper helper, string url)
    {
        string _out = String.Format(@"<script type=""text/javascript"" src=""{0}""></script>", url.ToMyCompanyUrlAction(helper.ViewContext.HttpContext));
        return _out;
    }
    public static string ToMyCompanyUrlAction(this string url, HttpContextBase context)
    {
    return String.Format("{0}://{1}{2}", 
        (context.Request.IsSecureConnection ? "https" : "http"),
        WebConfigurationManager.AppSettings["resources_url"],
        VirtualPathUtility.ToAbsolute(url, "/"));
    }
    

    We created helpers for MyCompanyResourceImage and MyCompanyResourceCss with suitable parameters for alt tags/media types etc. also.

    This means we can (from the outset) host via our own resources domain, and if in future we choose to move that over to a CDN, then we can do so with minimal fuss.

    Hope that helps someone.

    Cheers, Terry

Add Comment