Search code examples
cdnamazon-cloudfrontakamai

Is it possible to add logic to CDN


Is it possible to serve two different pages based on the user agent. I want to serve pagename-iphone.html if the user agent matches iPhone and pagename-other.html for all other user agents. I want all pages on the site to follow this pattern. Is it possible to do this at the CDN level (cloud front, akamai etc).

thanks for your help!


Solution

  • I think what you are after is User Agent based caching, like vary: User-Agent. In theory, a server provide Cache service can definitely do so, however, as far as I can tell CloudFront and most of other major CDN providers don' support so.

    The basic reason is very straightforward that the currently there are too many User-Agent header, and it's almost unique on every single browser, not mention the different versions of the same browser. If you purely do things based on the whole User-Agent, you will lost the benefit of CDN cache most of the time.

    Some of the more advanced servers allow you to add condition based on headers, for example, in Varnish, you can even add if,else logic for returning different values. But this is not available for majority of CDNs.

    In the other hand, you should not rely on CDN to return different html pages. CDN is more commonly used to accelerate artifacts (js/css/imgs) instead of the whole page.

    EDIT: Actually, I just recieved an email from AWS mentioned now CloudFront starts to support this:

    Mobile Device Detection: You can now cache and deliver customized content to your viewers on different devices (e.g. mobile vs. desktop) based on the value of the User Agent header.

    Please refers to: http://aws.amazon.com/about-aws/whats-new/2014/06/26/amazon-cloudfront-device-detection-geo-targeting-host-header-cors/ for more details.