Data loading

Export a data() function and its result appears as ctx.data in your render function. It runs at build time, and per-request in the dev server.

fetchWithCache

Building many pages against the same API? Import fetchWithCache from sitelo:

import { fetchWithCache } from 'sitelo'

export async function data({ params }) {
  const res = await fetchWithCache(
    `https://api.example.com/posts/${params.slug}`,
    { /* standard fetch options */ },
    { maxAge: 3600 }
  )
  return { post: await res.json() }
}

Options

Cache modes

Only GET requests are cached by default (pass a cacheKey to cache other methods). Error responses are never cached.