Skip to content

Use Hako CMS with Astro

To display Hako CMS entries on an Astro site, you fetch them from the Content API when a page is built. There are three ways to use it, depending on when you fetch.

Approach When you fetch Suited sites Where to host
With a static site When you build the site News, blogs, company sites, and other sites where it is enough for changes to appear a few minutes after publishing Anywhere you can host static files
With Cloudflare Workers When a page is opened Sites with many articles that cannot wait for a rebuild. Sites where you want changes to appear as soon as you publish Anywhere that can run JavaScript (the examples on this page use Cloudflare Workers)
Preview drafts Production at build time; only the preview pages when they are opened Sites where the people who update content want to check how it looks on the site before publishing Anywhere that can run JavaScript

If you are not sure, start by using a static site. You don’t need a server to run the site, and you fetch entries from Hako CMS only when you build.

Reading at build time and reading on the server differ as follows.

Aspect Static site Cloudflare Workers
Until published content appears Until the rebuild finishes (rebuild with a webhook) The next time the page is opened (except for the cache time)
Number of Content API calls Each rebuild, one per entry Each time a page is opened. Reduce it with a cache
Data transfer limit The Content API part is used only when you build The Content API part is also used each time a page is opened. See “Cache and data transfer” in Use with Cloudflare Workers
Where to put the API key Environment variables where you build The site’s server (a Secret on Cloudflare)

With any approach, images delivered from Hako CMS count toward data transfer each time a page is opened.

  • Content collections: You can use Hako CMS entries with Astro’s standard approach (getCollection). See Use with content collections
  • Images: Hako CMS can change the size and format of an image through the URL. You can serve images that fit the screen without Astro’s image transformation. See Display images
  • API keys: Do not put them in code sent to the browser. If you do not read drafts, use a key with only the [読み取り](Read) permission. See Create API keys and set permissions