Speed up Plone for iPhone and iPad delivery
This is only for Varnish users due to the fact that with Apache you can do this very easily.
The key is to remove the revalidation order in the cache controle response header if you detect an iPhone or an IPad as User-Agent
I'm using Varnish-2.1.2, therefore I have altered the original script from rudd-o.com to work with this version, because the syntax of varnish has changed.
Add the following sections to your default.vcl, normally located in /etc/varnish/default.vcl:
sub munge_iproducts {
if (req.http.User-Agent ~ "iPhone") {
set req.hash += "iPhone";
set req.http.For-iPhone = "iPhone";
}
if (req.http.User-Agent ~ "iPad") {
set req.hash += "iPad";
set req.http.For-iPad = "iPad";
}
}
sub customize_obj_for_iproducts {
if (req.http.For-iPhone) {
set beresp.http.For-iPhone = req.http.For-iPhone;
set beresp.http.Cache-Control = regsub(beresp.http.Cache-Control,", must-revalidate","");
set beresp.http.Cache-Control = regsub(beresp.http.Cache-Control,", proxy-revalidate","");
}
if (req.http.For-iPad) {
set beresp.http.For-iPhone = req.http.For-iPad;
set beresp.http.Cache-Control = regsub(beresp.http.Cache-Control,", must-revalidate","");
set beresp.http.Cache-Control = regsub(beresp.http.Cache-Control,", proxy-revalidate","");
}
}
Into your existing sub vcl_hash section, add:
call munge_iproducts;
and to the sub vcl_fetch section, add:
call customize_obj_for_iproducts;
Now restart varnish and you're done!

Author: