Generate static payloads at build time using useStaticData
#25206
maximilliangeorge
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This proposal is a follow up on an interesting discussion I had on Discord. I've been thinking about taking a stab at building this as a module, however I wanted to get some input on this before diving in, perhaps also checking to see if there are similar ideas already in the works.
The idea is basically to have add another hook for fetching data, similar to
useAsyncData
. However, this data would only be fetched at build time and the data would be served as a static JSON payload.This allows mixing dynamic and static data with even further granularity. It also ensures the data is available right after build, with no need for an initial request for caching the payload.
To give a concrete example where I would use this: I'm building a page where navigation should happen instantly by means of rendering the header and page title first, while the page body is loaded async. Since the page header and title isn't expected to change very often I can safely use useStaticData for the headers, combined with scheduled builds.
An alternative approach to this could be to enable some sort of advanced cache rules for useAsyncData that lets you cache the request at build time rather than runtime. This might actually be preferable since I could then revalidate the payload in the background – however, I'm guessing it's a bit more complex to implement, especially as a Nuxt module.
Beta Was this translation helpful? Give feedback.
All reactions