fbpx

Wordpress

Conditional HTTP GET for WordPress

by , , revisited on


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

Conditional HTTP GET is a feature of HTTP protocol that can help with both the performance and even saving bandwidth to your users.

There is WordPress plugin for the purpose: If Modified Since. However, it doesn’t really support the latest WordPress.

If your WordPress is recent enough, we recommend you to install the WordPress Cacheability plugin.

The plugin has zero configuration in regards to conditional HTTP GET. Once the plugin is installed and activated, your WordPress has support for this HTTP feature already.

Let’s confirm things are working well.

Verify that conditional HTTP GET is working with your WordPress

We have example commands to test it with this page.

First, check that the Last-Modified header is being returned by plugin:

curl -Is "https://www.getpagespeed.com/web-apps/wordpress/wordpress-performance-checklist" | grep -i Last-Modified

If there is “Last-Modified: Thu, 28 Jul 2016 10:09:35 GMT” returned (or similar), the plugin successfully sends the header in the response. If the output is empty, something is wrong.

Next, confirm that conditional GET request will return empty response with 304 Not Modified status:

curl -Is "https://www.getpagespeed.com/web-apps/wordpress/wordpress-performance-checklist" -H 'If-Modified-Since: Thu, 28 Jul 2016 10:24:45 GMT' | head -n1

Will output “HTTP/1.1 304 Not Modified”

But wait, we have Varnish installed, and since the page is likely to be cached, it’s Varnish that handles conditional GET. We want to make sure that our uncached page still supports conditional requests. Let’s bypass Varnish by prepending a cookie:

curl -Is "https://www.getpagespeed.com/web-apps/wordpress/wordpress-performance-checklist" -H 'If-Modified-Since: Thu, 28 Jul 2016 10:24:45 GMT' -H 'Cookie: wordpress_test=1' | egrep 'HTTP|x-Cache'

Will give:

HTTP/1.1 304 Not Modified
x-Cache: uncached

This means that the request is not returned by the Varnish cache and our PHP backend (WordPress) properly handles the conditional request.

Note: if things don’t work for you using this page as a test, make sure to adjust the date you’re checking with since this post will likely be updated later on and thus change its modification time.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: