Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.

https://developers.cloudflare.com/workers/learning/how-kv-wo...

> 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...).

Which to me is a GREAT deal!

Cache Object: https://developers.cloudflare.com/workers/runtime-apis/cache

Asset Mapper: https://github.com/cloudflare/kv-asset-handler/blob/master/s...

Lines 181 and 224


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.


Thanks! Was mobile can couldn’t figure out


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.


Wouldn’t Wordpress + cdn basically give the same performance but with more functionality.

The only time the request needs to hit the origin is if nobody fetched the page.


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.


There's now an official Cloudflare Wordpress plugin that makes sites hosted this way incredibly fast.

In the confidence it caches the HTML, and the plugin triggers a CDN purge when the HTML changes

Coupled with Cloudflare's standards support (TLS 1.2, H2, H3), and their image optimisation services it's really great for performance.

Just got to remember to disable many of the WP 'speed optimisation' plugins that may be installed as they actually can cause more speed issues.


It all depends...

But probably not against a static page.

Wordpress is still PHP and a Database and whatever crazy plugins, templates and front end builders are involved.

Depending on how much JAM you have in your STACK, your site/app may or may perform better than WP.

I build a ton of sites in Jekyll, which are static sites and not JAMSTACK. The two get conflated.


Assuming you leverage the KV store for some things that are read-write or very dynamic, it should perform better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: