Caching: Work the Server and Client Side, and Everyone Benefits

Published in Web Development on Thursday, July 22nd, 2004

A look at server and client-side caching, some good links and examples of how to and when to cache.

The progression

The beginning

When I first started designing sites, they were static, table based brochure sites consisting of 'not-very-many' pages. These sites tended to cache quite well on the client side once downloaded, and as such, client-side caching was never a problem.

As time past and projects grew, a little server-side caching magic in PHP allowed me (and many others) to build sites in PHP and output larger completely static sites at the push of a button. Client-side caching wasn't an issue, as the resulting site was, again, static.

The midlife

Little by little, however, the scope of our projects grew. Fully dynamic sites with hits to the server on every page became the norm. Site speeds were a bit slower, but hey, so were the sites of the competition!

Modern day

Caching and it's mysteries were forgotten, until now. I have been ignoring things like caching simply because I didn't know much about it, the sites of my clients competition were generally slower (thanks CSS!), and hey, my clients didn't pay me enough to look into caching and to implement it.

Well, with a little research and testing, it is clear to me that server-side and client-side caching are not difficult, and that with a little work you can have a new tool for your toolbox that will benefit the User, your Client and you!

A new edge for everyone, a new tool for the box

A site that displays that much faster than that of your clients' competition is only going to make them look better to their users, and you look better to your clients. That is, the benefit is spread all round:

Give yourself a competitive edge

For the mid-level web developer, using effective caching will give your sites an edge over your those of your competition. By developing an effective reusable caching strategy (in your programming language of choice) you need only build the tool once and then you're laughing.

Making it happen

I won't be diving into the specifics here, rather I will simply provide links to the sites out there that have some great information on caching.

Mark Nottingham

Marks website has an excellent explanation of client side (or web) caching.

Site Point - Harry Fuecks

Sitepoint offers up Chapter 5 of Harry Fueck's book, The PHP Anthology.

In this excerpt, Harry covers some of the basics of caching, goes into implementing some caching strategies, and, the real gem as far as I am concerned, discusses controlling client side caching with PHP and Apache.

Simon Willison

Once again, Simon has the goods. Have a look at Instant caching with PHP if you are interested in getting something testable up and running quickly.

When to make it happen?

Blogs

Blogs are tricky things to cache, though they are excellent candidates, in particular the busier ones.

Popular blogs that get a whole whack of requests every day can greatly reduce server load by caching their homepages and using chunked buffering for other aspects of their sites.

A client example

We have recently implemented caching on one of our clients sites (Masa International, redesign on the way!), to help give them an edge over their competition. Their area is quite competitive, so the easier the site is to use, hopefully the stickier it is.

Their site has a two-pronged server-side approach, in that the static brochure pages are permanently cached, while the search result pages and property listings are cached but regenerated daily, after the client uploads new data. We found that the cached search results were downloading faster than the dynamic pages, and that by controlling client side caching (see Harry's Article linked above) we were better able to cache pages in the clients browser.

Contingency design

A side benefit to all of this is that this is yet another good example of contingency design. Rather than have your site drop off the radar if your mySQL server blows a gasket, you could have a whole static version of your site available. In addition, you could download this static version at applicable intervals and have a complete functional backup in the case that a serious server malfunction were to occur.

Put it to work!

I waited possibly too long to dive into this area, and lets face it, for most mid-level website providers there's already a lot to keep on top of. However, once you have a developed, tested and proven caching method you will have another reusable tool that will benefit everyone involved in a clients website.

Comments and Feedback

A nice link for more info on HTTP requests and a PHP module for handling delivery of pages: HTTP conditional requests in PHP.

Home » Blog » Web Development

Check out the blog categories for older content

The latest from my personal website,
Mike Papageorge.com

SiteUptime Web Site Monitoring Service

Sitepoint's web devlopment books have helped me out on many occasions both for finding a quick solution to a problem but also to level out my knowlegde in weaker areas (JavaScript, I'm looking at you!). I am recommending the following titles from my bookshelf:

The Principles Of Successful Freelancing

I started freelancing by diving in head first and getting on with it. Many years and a lot of experience later I was still able to take away some gems from this book, and there are plenty I wish I had thought of beforehand. If you are new to freelancing and have a lot of questions (or maybe don't know what questions to ask!) do yourself a favor and at least check out the sample chapters.

The Art & Science Of JavaScript

The author line-up for this book says it all. 7 excellent developers show you how to get your JavaScript coding up to speed with 7 chapters of great theory, code and examples. Metaprogramming with JavaScript (chapter 5 from Dan Webb) really helped me iron out some things I was missing about JavaScript. That said each chapter really helped me to develop my JavaScript skills beyond simple Ajax calls and html insertion with libs like JQuery.

The PHP Anthology: 101 Essential Tips, Tricks & Hacks

Like the other books listed here, this provides a great reference for the PHP developer looking to have the right answers from the right people at their fingertips. I tend to pull this off the shelf when I need to delve into new territory and usually find a workable solution to keep development moving. This only needs to happen once and you recoup the price of the book in time saved from having to develop the solution or find the right pattern for getting the job done..