For the last couple months, I've used Cloudflare Workers Sites to host one of my static sites, and I'm planning to migrate several more onto it. For those who don't know, Cloudflare Workers is their service that answers web queries by running server-side javascript that you've uploaded. It also comes with Workers KV, a very fast key-value storage database (like redis) that the server-side javascript can query.
So then, they said why not just upload your static site into the KV database, where the key might be "/index.html" and the value is the html content of that page. Then have a short javascript that reads from that KV and returns the requested page. They wrote some client-side scripts to simplify the uploading, and Workers Sites was born!
I love how your content is automatically replicated to all of their datacenters and loads super-fast from everywhere in the world. I also love that it's really cheap.
But the downside is how some features in Cloudflare's control panel don't work if you're hosting your static site this way. For example, I wanted to use the Page Rules to redirect /page1.html to /page2.html. I also wanted to use Page Rules to set browser caching for *.jpg files. But it turns out that Cloudflare Workers execute code before the Page Rules feature does, so it doesn't work! I had to solve both issues by changing their default javascript to build in redirects and browser caching manually. Not too hard, but annoying.
> I love how your content is automatically replicated to all of their datacenters
Well, it feels like it's automatically replicated, but your KV content is usually only stored in a few select datacenters until it becomes popular (and is then available on all DCs). This process is usually fairly quick (<50ms for a 10mb file, based on my testing from about a year ago) so it's almost imperceivable.
> It is optimized for these high-read applications, only reaching its full performance when data is being frequently read. Very infrequently read values are stored centrally, while more popular values are maintained in all of our data centers around the world.
Exactly. Little more clarification here though I think...
Flexibility of Cloudflare KV reads in general still yield quick enough results and make doing a quick and dirty cache a pretty good use case IMHO.
But Worker Sites specifically also use the Cloudflare Worker Cache runtime API — aka, per each POP, first reads of a route (index.html, blah.css, cat.jpg) are from KV and THEN cached indefinitely cutting that time to like 10ms.
This is taken then even further by using ETAG matching to make BrowserTTL indefinite (304s not 200s) on all assets until cleared cutting repeat visitors (regardless of POP) to basically nothing. Though .html for some reason doesn’t respect this (I think...).
You can link to specific lines on GitHub by clicking the line number, then the ellipses, then 'copy permalink' (you can also shift-click to select multiple lines). It also links to the current HEAD commit so the code won't change on you later on.
I was thinking about doing the same recently. The big thing I wanted to test was the way they hide Worker spin up in the latency of the TLS negotiation.
Depends on what you mean by Wordpress+cdn. If your CDN is only caching your css and jpg files, then every page load still has to go back to your main server and talk to your database. This is how "standard" Cloudflare caching works. It's pretty good, but a page load from Australia would still have to travel all the way to your PHP+MySQL server in the US and back again.
To speed it up further, you can tell Cloudflare to cache your HTML pages. Now you've eliminated that round-the-world trip (for most visitors), but you've also lost some of the dynamicness of your site. At that point, you're basically building a static site by different means.
So then, they said why not just upload your static site into the KV database, where the key might be "/index.html" and the value is the html content of that page. Then have a short javascript that reads from that KV and returns the requested page. They wrote some client-side scripts to simplify the uploading, and Workers Sites was born!
I love how your content is automatically replicated to all of their datacenters and loads super-fast from everywhere in the world. I also love that it's really cheap.
But the downside is how some features in Cloudflare's control panel don't work if you're hosting your static site this way. For example, I wanted to use the Page Rules to redirect /page1.html to /page2.html. I also wanted to use Page Rules to set browser caching for *.jpg files. But it turns out that Cloudflare Workers execute code before the Page Rules feature does, so it doesn't work! I had to solve both issues by changing their default javascript to build in redirects and browser caching manually. Not too hard, but annoying.