Varnish and WordPress, Corner Cases

The Corner StuffWordPress Varnish Corner Case

My previous Varnish and WordPress post, Make WordPress Faster with Varnish Cache, was good introduction how to get your site fast. It still left some cases untouched. In this post I will look into these cases and fix them. Cases include some Varnish and WordPress configurations.

WordPress Caching with W3 Total Cache

This is very popular caching plugin for WordPress. It has lot’s of features that we can take advantage of. Why I’m installing another cache behind  Varnish? Well, they do not rule each other out. Varnish will use it’s cache better if server sends proper browser caching values. By default, WordPress will not take advantage of browser caching. With this, we can reduce requests to server and have proper TTL values for objects in  Varnish Cache.

Go ahead and install W3 Total Cache. It includes loads of features by default so don’t get exhausted. Take your time and browse around what’s where. You can find all the option from left side under Performance Menu.

W3 Total Cache also includes minifying tools so I uninstalled Better WordPress Minify. There’s loads of guides how to tune settings, so I’m not going to do that. Bare minimum you should be enabling is: minifying, page cache and browser cache.

 

Disable Caching for Logged In Users

You don’t want to cache content of your logged in users. Long story short: add this to your policy file.

Disable Caching for Search Results

Repeating my self: Don’t cache search results: add this your policy file.

Normalize Accept-Encoding Headers

By default, Varnish 4.0 will tamper your requests to add Accept-Encoding header to your requests. There’s still caveat on this. Browsers send Accept-Encoding headers different order and all get their own hash bucket in Varnish Cache. Waste of resources. Also we do not want to compress again compressed object. So, go ahead and add this your policy:

Graceful Content Refresh

If you use default configurations for refreshing of objects, you might get small delay when refreshing content from back end. This is why we must allow Varnish to fetch content asynchronously and replace object gracefully.

This is how it’s configured.

Health Check

One of the core features of Varnish Cache is to shield from misbehaving back end servers. Here’s basic configuration to enable health check.

Varnish and WordPress, Corner cases

In this post I’ve shown some cases that makes your web site even more stable and fast. Again you can find sources from Github.

Getting Started with Windows Phone 8 Development

Developers, Developers, Developers

Can I Have Some Links, Please.

Can I Have Some Links, Please

So, you got tools to getting started with Windows Phone 8 Development, but don’t know how to do it? How do I design my UI?  In this post I will try to answer to these questions. If you don’t know where to get tools, visit my previous Windows Phone 8 Development, Dark Side.

First Tutorial

I’m not going to  copy paste tutorials from Microsoft website here. Instead go a head visit Microsoft Development Site and make tutorial from there. Of course after you’ve read this blog post.

There’s two possible options to start:

There’s loads of resources loaded behind these two links, read them thoroughly.

Yes, you can do Windows Phone 8 Development with JavaScript. Though I’ve done WinaBlip, a Blipfoto application for Windows Phone 8, with C#. Reason is purely educational – I wanted to learn C#.

 

Port an Existing App

Surprise,  surprise, Microsoft have made tutorials and comparisons how to port your existing iOS or Android application to Windows Phone 8. Here’ s small introductory video:

Resources for porting  applications are not only Windows Phone 8 specific, but universal to whole Windows Runtime Platform. So, here’s the link to main website of porting applications:

 

Design Principles

There are some UI design principles than should be fallowed. They differ from iOS and Android and requires little a bit investigating. Some of the basic principles of UI design to Windows Phone 8 to get you started:

  • Don’t create buttons just for buttons, use UI elements as buttons.
  • Make your UI for Portrait and Landscape
  • Make your UI scale to different screen resolutions
  • Try to use UI with your thumb, if you can’t – redesign

Whole bunch of guides how to design your application properly can be found behind this link:

Take a look before you start making your million dollar app.

API

Every developer needs API description. Well, here it is, all-in-one:

 

Forum

We need forums, support from other developers. Here’s forum just for Windows Phone 8 Development:

 

Blog

If you want to fallow tips and tricks from Microsoft, subscribe to their blog:

 

Summary

Getting proper resources can be a bit tricky sometimes. Microsoft is trying to embed Windows Desktop, Phone and RT development which is causing some resources to be hidden inside Microsoft webpages. Luckily there’s somewhat active development community so you can always use google if you can’t find answer from Microsoft pages.

Here’s all links in one:

Python Tutorial

Here’s all of my Python tutorial in a one Post. There’s still some chapters to be written so I will add them also here when published.Python

Python is interpreted, high-level and very readable programming language. It supports object-oriented, functional and imperative programming. It does not include curly brackets to indicate scope. Python uses indentation to separate code blocks. Language rejects Perl philosophy: “there is more than one way to do it” in favour of  “there should be one—and preferably only one—obvious way to do it”.

Python Tutorial – Basics

Python Tutorial – Dictionaries

Python Tutorial – Lists

Python Tutorial – List Comprehensions

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 <lasse@varnish-software.com>. 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.

headers-m

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?