Skip to content

Node adapter sends Vary: Accept-Encoding even when not applicable #10343

Description

@xamir82

Describe the bug

The Node adapter currently sends back the Vary: Accept-Encoding header as part of the response (when files under /_app like .js and .css files are requested) even when the precompress configuration option is false; meaning even when the response won't vary based on the Accept-Encoding header of the request, which is what Vary: Accept-Encoding is supposed to indicate.

In summary, adapter-node should not include Vary: Accept-Encoding in the response if precompress: false.

Reproduction

Just build a SvelteKit Demo App with adapter-node and send a request using curl -i to some CSS/JS file, and examine the response headers.

Logs

No response

System Info

-

Severity

annoyance

Additional Information

No response

Activity

  1. dummdidumm commented on Jul 7, 2023

    @dummdidumm
    Member

    We don't set that header anywhere, which makes me think this is either from polka or sth else.

  2. xamir82 commented on Jul 7, 2023

    @xamir82
    Author

    We don't set that header anywhere, which makes me think this is either from polka or sth else

    Ah okay, then yeah I guess probably. Either way I'd say this should be considered a bug.

  3. theandrew168 commented on Jan 16, 2026

    @theandrew168
    Contributor

    It looks like this header is actually being added by sirv (behavior added in this PR). SvelteKit utilizes sirv with both gzip and brotli unconditionally enabled here. Looking at sirv's code, it looks like this header is added when gzip and / or brotli compression is generally enabled without also checking if a corresponding compressed file actually exists.

    I see two potential solutions (though I'm unsure which would be better / more correct):

    1. Only pass gzip: true and brotli: true to sirv when precompress: true is set
      1. This might cast too wide of a net and unintentionally impact other aspects of adapter-node that utilize asset compression
    2. Fix sirv to only add Vary: Accept-Encoding when a compressed version of the requested file is present
      1. This seems like the "more correct" approach to me (it'd also solve this for any other users of sirv)

    If a best approach can be agreed upon, I have the capacity to make either fix.

  4. added theissue type on Jan 16, 2026
  5. teemingc commented on Jan 16, 2026

    @teemingc
    Member

    Hi Andrew. I think both are correct based on the docs https://github.com/lukeed/sirv/tree/main/packages/sirv#optsgzip it says that the options should only be enabled for precompressed assets. So we should disable these if precompress is false.

    It also says that it looks for .gzip files but I don’t think it’s doing that at the moment.

    Feel free to submit a PR for both options! The Kit one might be easier to get done first

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions