Proposal: +initial-data.ts
hook (Usecase: is it possible to call +data
ONLY on first load)?
#1904
-
Question, is possible to ONLY call
|
Runs on | +data.ts | +initial-data.ts |
---|---|---|
First-load | Yes | Yes |
Succeeding client-side navigations | Yes | No |
I noticed simply putting in +data.ts
in the page's folder, will mean you block the first byte.
Demonstration of the problem, notice that...
- Going to "Page with Data" is 🐌 slow under network conditions. (It always fetches
index.pageContext.json
because it has+data.ts
) - Going to "Page with No Data" is always ⚡️ instant, no matter the network (always uses client-side navigation).
vike-data-blocking-first-byte.mp4
That's the idea. Let me know if you guys think there's actually already an existing way to do this with the current Vike APIs. Maybe I'm overthinking it.
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Alright cool. I actually found something in the docs for my usecase: https://vike.dev/pageContext.json#avoid-pagecontext-json-requests It was quite deep to find though.
|
Beta Was this translation helpful? Give feedback.
-
Indeed, I think there is room for improvement for this use case. It's very much on the radar and I've a couple of ideas.
👍 |
Beta Was this translation helpful? Give feedback.
Basically:
Here's a sample repo: https://github.com/Blankeos/vike-vs-next-ssr-experiment/tree/main/vike.
Personally works great for me.
cached.data.shared.ts.mp4
Alternative solution (I think would be easier), is just caching the
pageContext.json
.