Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Caching two versions of same page in Dispatcher


Level 2

Is it possible to cache two versions of the same page in Dispatcher. Akamai provides this capability called the dynamic page caching where they can have two versions of same page and based on some logic they will return one of them.

We cache our pages in Akamai. We have two kinds of users: cookied and non-cookied and they are shown different content on same page. When the page is sent to the browser from Akamai we run a JS code to determine the cookie value and if based on that we either show the cookied content or non-cookied content.

We want to change this so that browser is sent only the correct content. Now akamai can cache two versions of the same page based on cookie/non-cookie but we are not sure if Dispatcher has this capability??

3 Replies


Level 10

I have never read anywhere in AEM documentation that dispatcher supports this functionality. Lets see what other community members have to say on this use case. 


Level 10

Per my knowledge, the short answer is No.

Akamai uses ARL (Akamai Resource Locator) for creating cache keys which may be based on:

  • Typecode*
  • Forward [fwd] path (origin server, pathname, filename and extension)
  • Query string (Optional)**
  • Secure Network Delivery Indicator***
  • HTTP Method (GET, HEAD, etc.)

Dynamic Page Caching (DPC) enables the caching of HTML pages based on request path, query strings, cookies, and request headers. Using any combination of attributes from an HTTP Request, Akamai will decide when and how to cache the responses and serve them.  (Dynamic Page Caching: Beyond Static Content - The Akamai Blog)

Dispatcher doesn't provide these options and it just creates the cache keys with URL with option to ignore querystring or cache headers but doesn't allow to create cache keys with querystring or headers or origin etc.

A possible option could be to create multiple cache fragments for a single page/URL and based on querystring/headers/cookies, fetch specific fragments from dispatcher cache by manipulating the request paths either in apache rewrites or somewhere in the middle.

I haven't researched if Varnish/Nginx could achieve the similar. In any case, you'd need to have another solution in-place, if you really want to go down this route based on your requirements. It's not supported by dispatcher OOB.


Employee Advisor

Assuming, that it does not matter, if a user can access the page-without-cookie even if he should see the page-with-cookie. But of course he should see the right one.

My approach:

* page.cookie.html renders the the page for the users with the cookie being present.

* page.nocookie.html renders the page for the users without having that cookie.

* when you enter page.cookie.html, all links to other pages are rendered with the "cookie" selector; same behavior with the "nocookie" selector (you can do that either on the server or via javascript in the browser).

* you have Javascript on the webpage, which checks if the cookie is present or not; if the user is on the wrong page, it redirects to the correct version.

How it works:

* If a user enters the correct version of the page he will stay on this flavor for any subsequent click to other pages of the site.

* If a user hits the wrong version of the page (either following a deep link from an external site or by manipulation the address bar) he will get redirected once to the correct version.

That would require minimal Javascript for the initial redirect  plus the correct rendering of the links.