Tech Tip #47: Cache at every layer

Why send the same bytes a million times?

Video created by explainapaper.com

The problem

Responses that rarely change are regenerated and re-sent on every request: no cache headers, no CDN, no application cache.

The fix you can use today

  • Set Cache-Control headers on static assets, with long lifetimes and versioned file names.
  • Put a CDN in front of static content.
  • Cache expensive query results in the application where they can go slightly stale.

GreenCode researchers list missing caches as an energy waste to fix.

Tools that help

  • GreenCode Constitution skill (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
  • WebPageTest: loads a real page and shows every request, its size and when it loaded

How GreenCode helps

GreenCode helps tackle this by scoring a codebase against quality, security and green software patterns in one pass, so a missing cache comes out as a ranked defect alongside the bugs and security findings. More on this.

Tags

#caching#cdn#web-performance

Sources

Transcript

Why send the same bytes a million times? Many responses rarely change. Yet they are rebuilt and sent again on every request. No cache headers, no content delivery network, no cache in the app. Every request not made is energy not spent. On your servers, on the network, and on the user's device. Here is the fix you can use today. First, set cache headers on static files, with long lifetimes. Put a version in each file name, so a change gets a new address. Next, serve static content from a content delivery network. Then cache costly query results in your app, where slightly old data is fine. GreenCode's Constitution skill can help an AI coding agent spot missing caches. And tools like WebPageTest show every request a page makes, and its size. GreenCode researchers list missing caches as an energy waste to fix. GreenCode helps tackle this by scoring code against green software patterns in one pass. A missing cache comes out ranked, alongside bugs and security findings. That was GreenCode Tech Tip number forty-seven. Follow for the next tip, and find more on greencode.ai/tech-tips.

All GreenCode Tech Tips · All GreenCode videos

  • Tip #47
  • For Developers
  • Length 1:14
  • Category Web and front-end
GreenCode

Want this checked on your own system? Talk to the GreenCode team.

Get in touch