All posts by Timonen Jari

About Timonen Jari

Jari Timonen is an experienced software enthusiast. His experience includes successful team leadership combined with understanding complex business domains and delivering them into practice.

Make WordPress Faster with Varnish Cache

WordPress, Plugins and Varnish

Varnish to WP is like Christmas all year round
Varnish to WP is like Christmas all year round

My self, I don’t want to wait for website to load over 2 seconds. Standard installation of WordPress is, well, sluggish. Installing couple of plugins, nice theme and banner pictures makes it even more slower. It does not matter if your server is latest and the greatest. You can install plugin to minify some CSS and JS with Better WordPress Minify. Or you can optimize your images with EWWW Image Optimizer. Still there’s just too much going on with Worpress. All of this affect your readers – do they want to come back? Also it affects how high Google scores your site.

Varnish is an HTTP accelerator which is designed to boost up content-heavy dynamic we sites. It sits in front of your HTTP Server and caches your content automatically, almost. You can make wordpress faster and lower loads on your server. Win-Win.

Varnish has Domain Specific Language which compiles to C. You write set of rules how your content is cached and let Varnish do the heavy lifting. Current major version is Varnish 4 and VCL 4.0. If you still have 3.0, see this upgrade guide for changes to the DSL. This tutorial is using VCL 4.0.

Installing Varnish

I’m using Debian, and it’s stable release “Wheezy” has old Varnish 3. So I’m not going to use that. Instead go ahead and download latest version from the website for your OS whatever it might be.

Installing Varnish 4 to Debian:

Configuring Varnish

Go ahead and edit standard port and change it to 80. Don’t go changing your Apache port just yet. Let it run until you can make sure everything compiles ok.

If you’re not sure about your configs, you can configure Varnish to be in port 81, and test side-by-side without loosing any readers.

After that make a copy of the original VCL file:


Adding VCL Caching Policies

Add new file with the name default.vcl. See comments of default.vlc for more details how rules are working. This is bit and pieces taken from internet and combined. See definite quite from Varnish Documentation. There’s also lot’s of basic examples included in the documentation.

Default Policy


Device detection

Then device detection. This will ensure that mobile/desktop versions of your site will look as they should be. Code checks what kind of user agent browser has and sets device identification string to the headers. Then based on that string, in default.vcl, vcl_hash function generates separate cache for each device type.

This code does not include changing from mobile to desktop. That will be topic of a next blog post.

Add file called devicedetect.vcl to the same /etc/varnish directory. Original version of this can be found in GitHub, and it’s author is Lasse Karstensen <>. This is same code, but migrated to VCL 4.0.

Testing that Policies Work

If you’re doing this for the first time, you can just restart varnish to see if syntax is correct.

If you’re already running a version and you want to see if it compiles. This will output an error or C source code. After this, you can restart the server.

Configuring Apache

Edit your Apache, or favourite HTTP Server to use another port. (8080) Remember to check virtual host also configs.

Now go ahead and restart HTTP Server and Varnish. Varnish will be now serving at port 80, and Apache in 8080.  How Varnish knows where to look for HTTP Server? Well, look at the top of default.vcl.

Proof that it works

Well, you site should be blazingly fast! First load might take longer, but after that it should be rendering almost instantly. You can also investigate two headers: Age and X-Varnish. Age should be above 0 and X-Varnish should have two request id’s.


Purging Content from WordPress

Install Varnish HTTP Purge extension to your WordPress. You can purge manually or automatically when saving posts.

All you need to do is add this line to your wp-config.php file

Make WordPress Faster with Varnish Cache

Varnish Policies are in Github.

If you know how to install WordPress, you know how to install and configure Varnish Cache. You only need hour of free time and your readers will thank you.

Leave comments if you’re planning to install Varnish. Or if you have additional policies you want to share?

Windows Phone 8 Development, Dark Side

winablipI’ve always been fascinated by mobile development. I’ve been trying out Android and iOS but my interest run out to the fact that almost every software is already written. This is where Windows Phone 8 Development comes into picture. There is lot of room for new applications – free and paid. Though you might not become a millionaire, you will be almost certainly be the first.

So, I made my own Windows Phone 8/8.1 Application. It is a mobile version of Blipfoto – diary site to photographers. You take on picture a day, give it a description and share it. This is called ‘blip’. I’m frequent user of Blipfoto and my Lumia 1020 is taking nice pictures to share. Application is free of charge.

Windows Phone devices are not very good at browsing stuff. I might be a bit harsh to say this, but not supporting file upload in a browser is just a very big down side. This was the main reason I started to make Winablip, Blipfoto application for Windows Phone 8.

Starting is easy, go to Windows Phone 8 Development Site and download Visual Studio Express. This is what you need just to test things out. There’s emulator included in which you can test your apps. There’s still a one catch: You need processor that supports Second Level Address Translation (SLAT) among Hyper-v. This means that you need fairly new machine First processors to include this feature were  Intel Nehalem i3/i5/i7, AMD third-generation Opteron/Barcelona.

If you want to use your own phone for testing, you can unlock one phone for developer purposes. To publish your application you need to have developer account. With this account you can unlock up to three devices. Cost is only tens of dollars/euros. In Finland it costs 14€. This is a one time fee, no annual changes required.

In next Windows Phone 8 Development post I will introduce some key resources to get information.