nuxtlabs / vue-telescope-website

Discover Websites made with Vue.js
https://vuetelescope.com
46 stars 5 forks source link

feat: add SWR middleware #41

Closed atinux closed 2 years ago

atinux commented 2 years ago

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code

Resolves #32

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
vue-telescope-website ✅ Ready (Inspect) Visit Preview Aug 13, 2022 at 1:16PM (UTC)
atinux commented 2 years ago

Seems that we do have STALE answer 😊

One question @pi0. do you know why the cache-control sent back is not the same as the one defined in setHeader?

Screenshot 2022-08-12 at 23 50 44@2x

pi0 commented 2 years ago

It seems to me vercel revalidates in the background since s-maxage is set to 1 and returns a header to invalidate response. Any specific reason you are not using h3 utility?

atinux commented 2 years ago

Because I don't remember the utility to use :sweat_smile:

pi0 commented 2 years ago

It is handleCacheHeaders (and should be auto importable with latest nitro) shall I push?

atinux commented 2 years ago

From what I see in https://github.com/unjs/h3/blob/main/src/utils/cache.ts

How would it produce s-maxage=1, stale-while-revalidate=3599 ?

atinux commented 2 years ago

Updated to use handleCacheHeaders @pi0, let me know if good enough to merge now :blush:

atinux commented 2 years ago

Ouppps, I need to handle to disable caching is the user is authenticated :sweat_smile:

atinux commented 2 years ago

Tested and seems to work well now, merging for more testing (it is still not officially released)