robinmetral / website

Source code of robinmetral.com, built with brut
https://robinmetral.com
2 stars 0 forks source link

Optimize caching #12

Closed robinmetral closed 2 years ago

robinmetral commented 2 years ago

Optimize caching:

cloudflare-workers-and-pages[bot] commented 2 years ago

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 872b5ef
Status: βœ…  Deploy successful!
Preview URL: https://4c3aa1b3.robinmetral.pages.dev

View logs

robinmetral commented 2 years ago

Results

Tested with WebPageTest on the last post page, to include static assets like images in addition to stylesheet.

Before After
Optimization overview Flags uncached static assets All optimized
Plotted First Contentful Paint speed First runs avg. 1000ms, repeat runs avg. 775ms First runs avg. 1000ms, repeat runs avg. 50ms
First runs filmstrips
Repeat runs filmstrips Loads HTML for 700ms Instand load

Where the optimizations really shine is on repeat runs through HTML caching. A repeat run used to only cache static assets (for 4h, the Cloudflare default) but the HTML still had to be fetched because Cloudflare defaults to max-age:0. Caching HTML for 10 min basically means that a page reload load is instant (everything is cached).

Another improvement that isn't shown in tests is performance for a visitor coming back after 4 hours. Unless static, versioned assets have changed, only the HTML will be re-fetched while images and stylesheet will be pulled from the cache (like a repeat run in the "Before" scenario).