Speed Optimization in 4 Minutes

Step 5 - Back-End Code Optimization

You may have noticed that all of the tips so far have been optimizing the front-end, and there's good reason for that (85% of the time spent waiting for a page to load is on the front end. But now that we've tackled that we focus on the back end code.

  • Optimize database queries: Slow running sql is a hint that you need an index.
  • Cache server-side data: Consider keeping frequently requested data in a cache so you don't have to hit the database or disk.
  • Optimize server-side code: Find opportunities to make your server-side code more efficient, perhaps with better algorothms or early returns.
  • Optimize your tech stack: As frameworks mature they typically become more performant. Think about an upgrade, or fine tune some settings.

Let's see how this affected our stats:

Metric This Load Versus Last Step Versus Baseline
Time to First Byte (TTFB) - - - - -
Largest Contentful Paint (LCP) - - - - -
Page Complete - - - - -
Page Weight (transferred) - - - - -
Questions about these metrics?

Hover over the metrics above to see descriptions of each. Why didn't we choose other metrics, such as First Input Delay (FID) or Cumulative Layout Shift (CLS)? Simply because they were hard to represent in this demo. FID requires user interaction, which is tricky to fake. CLS is a lifetime metric (measured the whole time you're on the page, not just during load), so we can't report that until you leave the page. There are a lot of very important speed metrics and it's encouraged to get to know more than the few here.



Compared to the baseline, all the optimizations so far have affected the complete page load by -.


To ensure valid comparisons, we've placed a specific amount of hidden html comments here so the textual content of every step is the same length.

Optimization not as great as you think? Good observation. Sometimes speed optimization is trial and error. Not all steps work well for every website.