Skip to content

feat: add stale-if-error on served packages - #1426

Merged
ije merged 1 commit into
esm-dev:mainfrom
martcl:feat/stale-if-error
Oct 9, 2026
Merged

ije merged 1 commit into
esm-dev:mainfrom
martcl:feat/stale-if-error

Conversation

@martcl

@martcl martcl commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Issue:

Problem:
When esm.sh goes down, it is not realistically able to survive on cache. This is due to how the cache-control header is configured and how a lot of packages don't define a strict version for their dependencies. When requesting a package from esm you are able to define a strict version, but you don't control the versioning of transitive packages. They could be defined without a strict version, e.g ^0.27.0. This transitive package is required for your package to work, but is only cached 10 minutes, making fact that a striced versioned package is cached for a day not a good mechanism for surviving esm.sh downtimes.

Fix:
Adding stale-if-error directives to the cache-control header will give proxy/caches in front the ability to serve the content while the service is unavailable.

Change:

  • Add stale-if-error=86400 on cache-control header used to serve esm packages. This allows for a day worth of downtime.

@filipgolonka filipgolonka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@ije ije left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@midnight-wonderer

Copy link
Copy Markdown

Please ensure that Do not serve stale content while updating is set to off in Cloudflare.
I'm not sure if this affects stale-if-error, but it definitely affects stale-while-revalidate in my tests.

Also, it would be nice if we could address decision regarding asynchronous revalidation (stale-while-revalidate) in the original thread, as this PR does not cover that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants