# Server Side Rendering with Netlify Functions

**URL:** <https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [August 21, 2019, 9:22am UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897 "2019-08-21T09:22:29Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![ecomplus](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/ecomplus/32/16605_2.png) [@ecomplus](https://answers.netlify.com/u/ecomplus)\
**Post date:** [December 17, 2020, 11:48pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/28 "2020-12-17T23:48:58Z")

</div>

> [@Dennis](#):
>
> To answer your first question, cache is already purged on each deploy for assets hosted on Netlify. If you are proxying to another URL, we will use whatever caching value that the response gives us, so those assets may not be purged on deploy immediately, depending on the cache-control headers received.

Great, it was implemented recently?  
When I started using partial build and lambda function for SSR I think I tested it and the page that had been SSRendered continued to deliver the old version.  
I was using following `Cache-Control`:  
`public, max-age=60, s-maxage=2592000`  
The expectation is that after a new deploy the page URL hits the lambda function again, would that happen?

> Not using any proxy…

---

<div class="post-metadata">

**Author:** ![Dennis](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dennis/32/34_2.png) [@Dennis](https://answers.netlify.com/u/Dennis)\
**Post date:** [December 29, 2020, 5:18pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/29 "2020-12-29T17:18:08Z")

</div>

It was implemented very near from the start of Netlify, so it’s not a new feature.

If you are using that cache-control header, then your SSR page will be cached likely for 30 days since `s-maxage` overrides `max-age` for proxy caches. That’s likely why you are seeing the old version.

---

<div class="post-metadata">

**Author:** ![ecomplus](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/ecomplus/32/16605_2.png) [@ecomplus](https://answers.netlify.com/u/ecomplus)\
**Post date:** [January 5, 2021, 11:32pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/30 "2021-01-05T23:32:12Z")

</div>

> [@Dennis](#):
>
> If you are using that cache-control header, then your SSR page will be cached likely for 30 days since `s-maxage` overrides `max-age` for proxy caches.

Yup, it works, my point is about:

> [@Dennis](#):
>
> To answer your first question, cache is already purged on each deploy for assets hosted on Netlify.

I mean, I was expecting to cache SSR output for up to 30 days **or until a new deployment is triggered** , and I think it’s not working, just tested again 😐

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [January 20, 2021, 4:53pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/31 "2021-01-20T16:53:34Z")

</div>

Sorry this thread has been so long in waiting!

Whose cache are you talking about here?

- In your visitor’s browser cache, you’ll have no control over when it is re-fetched, after it receives the asset with the cache-control header.

- In our CDN’s edge cache, we aim to respect the header as well so I believe a redeploy will not change the fact that the cache was given a long timeout (or, said another way, our nodes will respect the cache like browsers).

- when something is NOT cached in the proxy - which is a per-CDN-node cache, and we have dozens of nodes including newly created ones with no cache - it will be fetched with the current header to the CDN node and cached according to the directive.

Our networking team has confirmed these assertions, so this should be your guiding light - if you need your function’s response to be easily/quickly removed from our CDN cache, you should not set long cache timeouts on that response. Perhaps a timeout of something more like 5 or 10 minutes would best serve your needs?

---

<div class="post-metadata">

**Author:** ![ecomplus](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/ecomplus/32/16605_2.png) [@ecomplus](https://answers.netlify.com/u/ecomplus)\
**Post date:** [February 4, 2021, 3:14pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/34 "2021-02-04T15:14:19Z")

</div>

Hey @foot ,

Okay, I know your suggestion works, our current implementation is already setting only 10 min of maximum cache age, but it’s still not the best scenario.

I’m trying to deploy a JAMstack but with lot of views, so building entire site on each content change is not a good practice because it requires long time, then we’re building most important pages plus up to 300, the rest is SSRed, but as a JAMstack it doesn’t change until the content changes and a new deploy is triggered.

Currently we’re calling lambda functions much more than necessary because new deploys doesn’t purge cache, consequently I can’t set a long cache rule and the same slug is being SSRed many times unnecessarily as the content is not changed at all.

Additionally, without `stale-while-revalidate` and with a short cache rule, is common to take “long” time to access not pre-rendered views because they have to be SSRed again and again…

So, your suggestion works and it’s what we’ve been using for some time, but it uses unnecessary resources and at the same time results in slower server responses 🙁

---

<div class="post-metadata">

**Author:** ![Scott](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/scott/32/26136_2.png) [@Scott](https://answers.netlify.com/u/Scott)\
**Post date:** [February 15, 2021, 11:32pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/35 "2021-02-15T23:32:18Z")

</div>

Hey @ecomplus ,

Cheers for your patience. We’ve got a feature filed internally for this and we’re working hard to bring the best solution to fruition. I can’t put timeframes on any of this, regrettably, but do take my word that it’s on our radar and we’re exploring our options.

---

<div class="post-metadata">

**Author:** ![aj-circadence](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@aj-circadence](https://answers.netlify.com/u/aj-circadence)\
**Post date:** [September 21, 2021, 6:10pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/36 "2021-09-21T18:10:53Z")

</div>

@Scott any update on this? We experience the same thing… Wondering if this got implemented.

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [September 22, 2021, 4:04am UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/37 "2021-09-22T04:04:51Z")

</div>

Hi @aj-circadence,

New to this thread - so haven’t read through everything yet, but does this look like something that might help you: [On-demand Builders | Netlify Docs](https://docs.netlify.com/configure-builds/on-demand-builders/)?

---

<div class="post-metadata">

**Author:** ![Simonpedro](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/simonpedro/32/48208_2.png) [@Simonpedro](https://answers.netlify.com/u/Simonpedro)\
**Post date:** [February 23, 2023, 4:53pm UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/39 "2023-02-23T16:53:39Z")

</div>

Hello,

I’ve been trying long and hard to use the `stale-while-revalidate` cache control extension with Netlify, and didn’t succeed, so I ended up in this thread. Adding support for stale-while-revalidate would be very appreciated, since it would allow developers to implement ISR by only using cache control headers (as a Remix.run user, this is my preferred way to go):

```auto
Cache-Control: public, max-age=1, s-maxage=1, stale-while-revalidate=31536000

```

(CDN always returns a stale response, which is very fast, and in the background fetches the fresh data for the following requests)

On demand builders wouldn’t work for my use case.

Thanks

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [February 26, 2023, 11:27am UTC](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897/40 "2023-02-26T11:27:08Z")

</div>

> [@Simonpedro](#):
>
> On demand builders wouldn’t work for my use case.

On Demand Builders are the only way we’re providing anything close to stale-while-revalidate as of now. Any specific reason why it won’t work for you?

[Previous page](https://answers.netlify.com/t/server-side-rendering-with-netlify-functions/2897.md?page=1)
