Skip to content

How to avoid duplicate API requests from both Server and Client sides using the @tanstack/vue-query package in Vue? #8738

Answered by DamianOsipiuk
Danny-Tseng asked this question in Q&A
Discussion options

You must be logged in to vote

https://tanstack.com/query/latest/docs/framework/vue/guides/ssr#staleness-is-measured-from-when-the-query-was-fetched-on-the-server

A query is considered stale depending on when it was dataUpdatedAt. A caveat here is that the server needs to have the correct time for
this to work properly, but UTC time is used, so timezones do not factor into this.
Because staleTime defaults to 0, queries will be refetched in the background on page load by default. You might want to use a higher
staleTime to avoid this double fetching, especially if you don't cache your markup.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Danny-Tseng
Comment options

Answer selected by Danny-Tseng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants