Improve readme regarding "stale-while-revalidate" used in this project
See original GitHub issueCan someone explain a bit more about stale-while-revalidate
is used in this project?
I found i very hard to understand how it works in this example.
the now.json file:
"routes": [
{
"src": "/api/(.*)",
"dest": "backend/api/$1"
},
{
"src": "/auth/(.*)",
"dest": "backend/auth/$1"
},
{
"src": "/backend/(.*)",
"dest": "backend/$1"
},
{
"src": "/_next/static/(?:[^/]+/pages|chunks|runtime)/.+",
"continue": true,
"headers": {
"cache-control": "immutable,max-age=31536000"
}
},
{
"src": "/static/models/(.*)",
"dest": "frontend/static/models/$1",
"headers": {
"cache-control": "immutable, max-age=31536000"
}
},
{
"src": "/(.*)",
"dest": "frontend/$1",
"headers": {
"cache-control": "s-maxage=31536000, maxage=0, stale-while-revalidate"
}
}
],
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Improve caching on raw endpoints (#263246) · Issues - GitLab
I understand we need to set headers to prevent caching, when on a branch, but this is unnecessary when using strong ETags.
Read more >How to Write a Good README File for Your GitHub Project
In simple words, we can describe a README file as a guide that gives users a detailed description of a project you have...
Read more >How to write a good README for your GitHub project?
Today we will focus on good practices of writing such a file - with a few examples, and a ready to use template....
Read more >How To Create Beautiful and Useful ReadMe Documents For ...
Creating a readme file sounds easy, and that is usually the case. However, creating a good, useful and on point readme file is...
Read more >React polling example - cosmeticaiaconisi.it
Mar 24, 2021 · We have covered how to create React graphs using as an example ... anyone can catch fire using it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@TommySorensen We know that Zeit purges the cache when a new alias is created or an existing one is updated and when
s-maxage
is reached. Let’s keep this in mind as it helps reason around the behaviour you are seeing.When you reload using F5, the browser tries to do everything it can to obtain a cached copy from some cache (browser cache, shared cache [CDN], …, origin). In your case, the shared cache sees caching related headers (such as If-Modified-Since, etc) and responds with the content it has which is outdated as you mentioned. Why is it outdated even though your lambda has new data? Well, my guess is that while your lambda does indeed have new content every month, you don’t redeploy the lambda every month and the cache doesn’t get purged of old data. Furthermore, since there’s a big mismatch between how long content is fresh from the lambda’s perspective (1month) and how long the content is fresh from the shared cache’s perspective (~12months), you end up with the behaviour you’re seeing when you hit F5.
When you reload using Shift + F5 or Ctrl + F5 or Cmd + Shift + R, etc, the browser tries to bypass all the caches (by setting or unsetting certain headers such as
cache-control: no-cache
, noIf-Modified-Since
,Pragma: no-cache
, etc) which results in the shared cache being bypassed and your lambda being hit. Which in turn leads to fresh content being delivered with a200 OK
directly from the origin ie your lambda.Thanks @zeusdeux That really helped. One thing i cant seem to get working is that if i cache everything in the frontend folder
/(.*)
for 365 days, and I browse to the website within the 365 days, is that if I reload the URL (only f5), it will always give me back the “old” data with an 304, even thought i changed the data in that lambda that is fetching something that changes on a monthly basic. But if i ctrl+f5, i will get a 200 response with the new data. So the lambda is working, but is always returning the cached state.