So you want to serve smartphone-optimized HTML pages to your mobile users – and you want them served fast?
Simply install Varnish and let it do device-type detection and caching for you! Just follow these few steps:
1. Install Varnish from https://www.varnish-cache.org/
2. Add https://github.com/varnish/varnish-devicedetect/blob/master/devicedetect.vcl to your default.vcl file
3. Add the code below to the beginning of the vcl_recv function:
1 |
call devicedetect; |
4. Finally, add this code to the beginning of the vcl_hash function:
1 |
hash_data(req.http.X-UA-Device); |
Now you can use the “X-UA-Device” request header in your app server to automatically detect desktops, tablets, and mobile phones and build HTML code optimized for each device type!
We are excited to announce a new addition to the upcoming Varnish summit in Oslo, May 7th.