Saving on Web Hosting with Browser Caching

Dollar bills falling against a blue sky

Companies that operate heavily trafficked Web sites can save thousands of dollars every month by making better use of browser-side caching.

Large Web sites pay for bandwidth at their Web hosting data center and also at their content delivery network (CDN, e.g. Akamai, Limelight, CDNetworks). Bandwidth costs add up to huge monthly bills. A site paying for a fixed bandwidth allowance may see no immediate bill reduction while it stays below that allowance. Large sites paying for usage or overages have a direct financial reason to address and monitor repeated transfers; smaller sites still benefit from faster pages.

Why caching gets overlooked

  • An incomplete understanding of all technology cost drivers and their impacts on each other. For example, a programmer may think they are saving the company money by architecting an application in a way that it requires minimal hardware servers, but not realize that the same design actually results in even higher costs elsewhere like CDN bills.
  • Busy development teams working on multiple projects on tight timelines. This results in compromises between product features/timelines and technical/architectural best practices/standards.
  • Web content management and presentation platform(s) that have evolved over the years
  • Staff churn over the years and an uneven distribution of technical knowledge and best practices about the Web site(s)
  • The continued following of some obsolete “best practices” and standards that were established long ago when they were beneficial, but are now detrimental.

At a complex Web site, an investigation can uncover problems the team did not know about, or show that a familiar problem costs far more than expected.

One such problem is repeated delivery of static objects that the browser could reuse. Some reach the browser from a CDN cache; others travel all the way from the origin servers on every request. A fresh browser-cache entry can avoid the network request altogether. An expired entry with a validator can be checked with a conditional request: a 304 Not Modified response avoids sending the body again, but still involves a network exchange.

The costs of unnecessary transfers

  • They slow down your Web pages. Instead of the browser being able to use local copies of these objects, it has to fetch them all the way from your origin servers.
  • Unnecessary load on origin Web servers and network equipment at the Web hosting facility. This can be an especially severe problem when a Web site experiences a sudden many-fold increase in traffic caused by a prominent incoming link on the home page of a high-traffic site like Yahoo, MSN or Google.
  • Additional storage in logs at the origin Web hosting locations’ servers and other devices.
  • Avoidable processing and transmission through origin servers, network equipment, the CDN and the Internet to the browser. Reducing this work also avoids wasting energy.

A few objects can create a substantial bill when millions of pages repeatedly download them. Consider a worked example: avoiding 200 million transfers of a 100,000-byte file in a month saves 20,000 gigabytes of payload, using decimal gigabytes. At an illustrative marginal charge of $1 per gigabyte, that is $20,000 in a month. Use your own transfer counts and contract rates; a fixed monthly commitment may leave the bill unchanged until you can reduce the commitment or avoid an overage.

For technology managers

  • Make browser caching a team-wide practice. Show engineers how repeated downloads affect your actual bill, and use those calculations in design reviews and in the cleanup of existing pages.
  • If the problem is widespread, make the cleanup a formal project. Present finance and business management with the expected savings, performance gains and engineering effort. In this economy, that is a strong case for funding the work.

For engineers

  • Read the article about optimizing caching at Google Code and the HTTP/1.1 caching specification. Use Cache-Control or Expires to set freshness, and ETag or Last-Modified to validate a cached response. Give changed static assets new versioned URLs and update the pages that reference them. Use private to exclude shared caches, and no-store when a response must not be stored.
  • Review any objects that are served by origin servers every time for legacy reasons that may now be obsolete.
  • Combine JavaScript files that your pages use together and that change together; apply the same reasoning to external CSS. A shared file can reduce HTTP requests and be reused across pages. Combining unrelated or frequently changing files can instead force visitors to download unused or unchanged code again.
  • Study Steve Souders’s Even Faster Web Sites: Performance Best Practices for Web Developers. Share these recommendations and hold a discussion with your tech and production colleagues.