Skip to content

Allow for SSR response caching #360

Open
@macgors

Description

@macgors

Is your feature request related to a problem? Please describe.
Right now, I don't see an option to tell Netlify to cache my responses from SSR running on edge functions.
Acording to Netlify's docs

There are two parts to configuring an edge function for caching:

Opt in to caching by setting the cache property to manual
Customize cache behavior by specifying HTTP headers

While the second part is straightforward (for example by using Angular's server routes, the first part is problematic.

In src/helpers/setUpEdgeFunction.js the actual function is created with no caching enabled and no option to change that.
Using netlify.toml based configuration is at the very least hard for users.
I think it might be impossible, after reading docs and this repo's source this seems like a file that should work:

[[edge_functions]]
  cache = "manual"
  function = "angular-ssr"
  path = "/.netlify/internal/edge-functions"

I think that this function cannot be targeted by file-based configuration, as this is not 'real' function in my repo.

Describe the solution you'd like
Configure edge functions to use manual caching out-of-the-box.

Describe alternatives you've considered
If I'm mistaken, an there is a way to target SSR edge function in my netlify.toml, please advise how.

Even if that's possible, I still see no reason as to why caching shouldn't be manual by default here. This won't break anyone's setup or won't cache things that shouldn't be cached, as you still need to add the required headers to the response.

import { RenderMode, ServerRoute } from '@angular/ssr';
export const serverRoutes: ServerRoute[] = [
  {
    path: 'products',
    renderMode: RenderMode.Server,
    headers: {
      'Netlify-CDN-Cache-Control': 'public, max-age=600, stale-while-revalidate=60',
    },
  },
];

The netlify.toml snippet I posted above is placed in my app's root and I've set Package directory to apps/my-app. Netlify.toml is read during the build, but has no effect on caching. In edge logs I can see that each request invokes the function.
My response from const result = await angularAppEngine.handle(request, context) contains the headers I've set up. They are however not present in the actuall response from the function to the browser.

Im using NX, angular 19 and App Engine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions