Attention

This document was written for an old version of Plone, Plone 3, and was last updated 207 days ago.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Speed up Plone for iPhone and iPad delivery

by Daniel Dietz last modified Oct 27, 2012 01:21 PM
How-to use Varnish to speed up delivery to your IProduct users. This Tutorial is based on http://rudd-o.com/en/linux-and-free-software/how-to-really-speed-up-plone-for-your-iphone-readers

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!


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.