Skip to content

Conversation

@theandrew168
Copy link

@theandrew168 theandrew168 commented Jan 17, 2026

Hello there! This PR relates to a downstream bug in SvelteKit. While an in-project fix was found, I think the logic used here in sirv for adding the "Vary: Accept-Encoding" header could be improved.

Today, the header is always added to the response if either opts.gzip or opts.brotli are enabled. However, for files that don't have an alternative, compressed version to serve, adding this header means that CDNs and Web Caches are unable to safely cache the file.

The fix applied by this PR updates the logic to instead ensure that both:

  1. The chosen file is compressed
  2. The chosen file is different from the requested file

This way, the "Vary: Accept-Encoding" header will not be added for files without compressed version OR for compressed files that are requested directly.

// and was chosen instead of the requested file.
const isChosenFileCompressed = !!data.headers['Content-Encoding'];
const doesChosenFileMatchRequestedFile = data.abs.endsWith(pathname);
if (isChosenFileCompressed && !doesChosenFileMatchRequestedFile) {
Copy link
Author

Choose a reason for hiding this comment

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

After a second look, !doesChosenFileMatchRequestedFile might alone suffice for this check since choosing a compressed version of a requested file is the only reason they'd differ.

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.

1 participant