Hi @all,

We are using you excellent module in a reverse proxy scenario. This leads to the following problem, when the redirect is forced to use the correct cookie value:

User requests page
-> Result is last cached HTML output from proxy (may not contain the correct responsive image URLs, if last caching acces was done in another responsive layout)

At this point the user only comes as far as the proxy and does not reach the application server and PHP itself. As a result: The cookie is not getting set and it will end up in an infinite redirect loop until the user eventually requests the page when it is not cached on the proxy anymore.

One solution would be to include the Cookie value in the cache key, but tis is not really useful in our scenarios, as our proxy servers handle hundreds of sites, which may not use this scenario.

So what do you think about making the redirect URL unique by adding a random portion at the end:

var random = Math.random() * 100000000;
location.replace(location.href + (location.href.getIndexOf('?') == -1 ? '?' : '&') + random);

I'd appreciate your comments on this

Thanx in advance & cheers

hctom

Comments

attiks’s picture

On nginx we solved this by adding the cookie to the cache key, so it was unique for each possible value of the cookie, I assume varnish can do the same?

attiks’s picture

Status: Active » Closed (works as designed)
alexiswatson’s picture

For future readers: It is indeed possible in Varnish, and the solution is more or less the same: ensure this cookie value (be sure to strip everything else out!) is included in the parameters used to generate the cache key. You will essentially have a cache bin for each URL and each breakpoint/preset.

Note that you normally won't want to worry about cookies when caching dynamic content, though I (along with others I've spoken to) have yet to find a more elegant way to handle this.