Closed NilsJacobsen closed 4 months ago
"The data()
hook is only meant for fetching the initial data of a page (in technical words: the SSR data). For other use cases see the sections below API routes and RPC." -> https://vike.dev/data-fetching
The data hook is meant for initial page load. We should probably switch to rpc for this again.
Can we cache from the data hook in vike? Gonna check.
No, rpc has nothing to do with this. You are running code on the server already, you don't need rpc. (RPC means you query client side to the server for things that can be queried on the client. You are already running the query on the server.) You need to cache the data. You have two options:
let cachedProjectCount = undefined
let cacheLastSet = undefined
export function data() {
if (cacheLastSet is newer than 24 hours){
return cachedProjectCount
} else {
cachedProjectCount = queryPostHog()
cacheLastSet = now()
}
}
Well with rpc you could run it from the client, to let it not influence the navigation times. But well I like your first proposal. Let me try integrate it.
Well with rpc you could run it from the client, to let it not influence the navigation times
Yeah but now you increase the loading time by shipping more JS to the client for a query you will execute on the server anyways
True but I felt like the js is not causing nearly as much time then the api call. But yeah let's try the variable solution.
-> Load it async or cache to not disturb the navigation experience