Astro adapter with on-demand builder not caching

After some research I undestood that it is possibile to deploy a website with Astro on Netlify with Server Side Rendering.

Reading the documentation it seems it is also possible to use Netlify On-Demand builder to build pages on demand and then cache them on the CDN.

I tried to implement this feature but it doesn’t seem to work. Can somebody knows why?

Here is my code:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import netlify from "@astrojs/netlify/functions";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: netlify({
    builders: true,
  })
});
// netlify.toml

[build]
  command = "yarn build"
  publish = "dist"
// src/pages/index.astro

---
import Layout from "../layouts/Layout.astro";

const response = await new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve(7);
  }, 2000)
});
---

<Layout title="Welcome to Astro">
  <main>MAIN {response}</main>
</Layout>

The setTimeout is for emulating an async method that takes some times.

After deploying with:

ntl deploy --prod

I see the page waiting 2 seconds before delivering the HTML.

However I would expect the Netlify On-Demand Builder to cache it and then not wait 2 seconds anymore.

What am I doing it wrong?

Without seeing the site, I can’t say much. But Astro writes and maintains its integration for Netlify. If that’s not working, they’re your best point of contact.

This is the website: https://tasty-transit.netlify.app/

That site is not using On Demand Builders. It has a single redirect that’s redirecting to /.netlify/functions/entry. Paths at /.netlify/functions are not builder functions. This is an Astro issue. They need to redirect to /.netlify/builders.

1 Like