lemmy-ui icon indicating copy to clipboard operation
lemmy-ui copied to clipboard

Error pages should not be cacheable

Open MrKaplan-lw opened this issue 8 months ago • 0 comments

Requirements

  • [x] This is a bug report, and if not, please post to https://lemmy.ml/c/lemmy_support instead.
  • [x] Please check to see if this issue already exists.
  • [x] It's a single bug. Do not report multiple bugs in one issue.
  • [x] It's a frontend issue, not a backend issue; Otherwise please create an issue on the backend repo instead.

Summary

I noticed that error pages like 404 currently can be cached if they match the patterns for caching logic, up to a day depending on the URL. This can especially be a problem when running multiple Lemmy-UI containers and doing a rolling upgrade where some containers may still be using the old version and others are already on the new version, as a user might get the main page served from an updated container but the request for loading static assets like CSS files is routed to an old container, which doesn't know about the path.

Steps to Reproduce

  1. Open https://lemmy.ml/style.css
  2. Get 404 response that can be cached for a day

Technical Details

The cache-control header is currently added with no consideration of the response being a success response:

https://github.com/LemmyNet/lemmy-ui/blob/main/src/server/middleware.ts#L46-L63

It might be possible to defer setting the header to the end of the response via res.end and then evaluating the status code: https://stackoverflow.com/questions/41009876/get-status-code-in-express-middleware

Lemmy Instance Version

0.19.11

Lemmy Instance URL

No response

MrKaplan-lw avatar May 07 '25 09:05 MrKaplan-lw