hermet hermet SSR. Islands. Rust.

What Hermet is

Cloudflare Workers is a service that runs programs on Cloudflare's servers. One program that you deploy there is called a Worker. In Hermet, you write the code that prepares a page's data in Rust, and you write how the page looks in an HTML template.

Building the HTML on the server when a page is requested is called SSR (server-side rendering). For example, on a statute page, the Worker reads the text of the statute from a database and renders the layout and the body together into HTML. The cache is what stores the finished HTML for a while. If the HTML can also be used when another person opens the same URL, the stored result can be reused.

To add something like the signed-in user's name, the server renders a per-user part. If you want the screen to change when someone presses a button, you can give that part JavaScript that runs in the browser. This idea of handling each place that needs it as an independent part is called Islands.

The page function for the shared HTML does not receive the user's session (login state) or cookies (values that the browser sends). Pass per-user data to a Server Island, which can receive the session. This separation makes it easier to keep per-user HTML out of the shared cache. The data that your site chooses to share must also be the same for everyone who can view the same page.

Where this design helps

  • On a product page, you can reuse the shared HTML with the product name and price, and add the number of items in the cart with a Server Island.
  • On a members-only page, you can check that the person may view the page, and then return the shared HTML that this person is allowed to see.
  • For pages whose content is fixed when you deploy, such as documentation, you can render the HTML as files at build time and serve them.