#Global data

5 messages · Page 1 of 1 (latest)

vague veldt
#

Hello,

What are my options if I would like to fetch data (from Statamic CMS) on initial app load and store it globally so that I can access it anywhere in my app? I have now used a middleware to fetch and store in Astro.locals , but a middleware is called on every request and that seems a bit overkill for data that doesn't change much.

I couldn't find anything on the web, except for the Astro.locals.

Any help is appreciated! 🙂

forest sentinel
#

on initial app load
do you mean on build?

vague veldt
#

I mean on first page load, whichever page is requested first.

vague veldt
#

Let's say I want to fetch company information from a CMS and show it in a several components (header, footer, etc). What would be the best aproach to only fetch this information once?

forest sentinel
#

yeah doing it in a middleware and putting it in locals makes sense to me