Skip to content

Blazor WASM on IIS Express: Unable to correctly rewrite content-encoding of precompressed static file #67884

Closed

Description

@jonganej

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have racked my brains on this issue for a whole day but seem to have no success on this. Previously being on .NET 8, I was able to serve a WASM web app for local dev with precompressed Brotli files with extensions like .wasm.br, .js.br, .data.br (Unity webgl artifacts) without a problem using IIS Express with the following web.config (see below). As expected, all of the above precompressed files would be served with the expected content-type and encoding.

Now after upgrading to .NET 10, the file wwwroot/assets/webgl/Build.framework.js.br returns a 200 with the correct raw data (brotli-encoded JS), with content-type: text/javascript (correct) and content-encoding: gzip (wrong). Because of the wrong encoding returned, the browser does not automatically decode the brotli compression to show a normal JS file (which is what my application expects).

All other files with .wasm.br or .data.br seem to correctly pass through the PreCompressedBrotli condition on IIS. I sanity-checked it by changing it to something else like value="foo" and it reflects when fetching said resources.

Interestingly enough, if I specify a non-existent filename like Foo.framework.js.br, the response is (obviously) 404 with the correct br encoding, implying that that filename does go through the intended rewrite section.

Is there a something new on .NET 10 that changes how static files are served?

<!-- web.config -->
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <outboundRules rewriteBeforeCache="false">
        <rule name="Set content type of compressed JS" preCondition="PreCompressedJs">
          <match serverVariable="RESPONSE_CONTENT_TYPE" pattern="^$" />
          <action type="Rewrite" value="text/javascript" />
        </rule>
        <rule name="Set content type of compressed WASM" preCondition="PreCompressedWasm">
          <match serverVariable="RESPONSE_CONTENT_TYPE" pattern="^$" />
          <action type="Rewrite" value="application/wasm" />
        </rule>
        <rule name="Set content type of compressed data" preCondition="PreCompressedData">
          <match serverVariable="RESPONSE_CONTENT_TYPE" pattern="^$" />
          <action type="Rewrite" value="application/octet-stream" />
        </rule>
        <rule name="Set content encoding of brotli files" preCondition="PreCompressedBrotli">
          <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern="^$" />
          <action type="Rewrite" value="br" />
        </rule>
        
        <preConditions>
          <preCondition name="PreCompressedJs">
            <add input="{PATH_INFO}" pattern=".*\.js\.br"/>
          </preCondition>
          <preCondition name="PreCompressedWasm">
            <add input="{PATH_INFO}" pattern=".*\/assets\/webgl\/.*\/.*.wasm\.br"/>
          </preCondition>
          <preCondition name="PreCompressedData">
            <add input="{PATH_INFO}" pattern=".*\/assets\/webgl\/.*\/.*.data\.br"/>
          </preCondition>
          <preCondition name="PreCompressedBrotli">
            <add input="{PATH_INFO}" pattern=".*\.br" />
          </preCondition>
        </preConditions>
      </outboundRules>
    </rewrite>
  </system.webServer>
</configuration>

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

.NET 10.0.10

Anything else?

No response

Activity

  1. added theissue type on Jul 17, 2026
  2. added
    area-blazor
    on Aug 26, 2026
  3. added this to the Backlog milestone on Aug 31, 2026
  4. oroztocil commented on Sep 2, 2026

    @oroztocil
    Member

    Hi @jonganej. Sorry for the late response, we did not see the issue before due to a triaging mistake.

    The change in behavior that you observe follows from a change made in .NET 9, where the Blazor WebAssembly dev server started serving wwwroot through static web asset endpoints (MapStaticAssets) instead of the static file middleware. A side effect is that .br files now get a content type assigned, where previously they got none. The SDK maps *.js.br to the content type of the decompressed payload, so your file is now served as Content-Type: text/javascript.

    By default, IIS Express has text/* enabled in its httpCompression configuration, while */* is disabled. So once the response is labeled text/javascript, IIS dynamic compression kicks in, gzips your already brotli encoded bytes, and sets Content-Encoding: gzip. Your outbound rule only fires when that header is empty, so it never runs. On the other hand, .wasm.br and .data.br are labeled application/wasm and application/octet-stream, which fall through to the disabled */* entry, so IIS leaves them alone and your rule applies.

    To work around this, the following methods should help you.

    a) Turn off dynamic compression just for the folder holding your precompressed assets. Your existing rules keep working, and the rest of the app still gets compressed normally:

    <location path="assets/webgl">
      <system.webServer>
        <urlCompression doDynamicCompression="false" />
      </system.webServer>
    </location>

    b) Or turn it off for the whole app, if you do not need dynamic compression anywhere:

    <urlCompression doDynamicCompression="false" />

    c) Or place the uncompressed Build.framework.js next to Build.framework.js.br. That makes the SDK recognise the .br as a compressed representation and emit Content-Encoding: br itself, which in turn stops IIS from compressing it. With this in place your outbound rules become unnecessary and can be removed entirely. The tradeoff is that you are shipping both copies, which may not be worth it for large Unity artifacts.

    The last workaround is based on a quirk that we should probably investigate as an SDK bug: When only Foo.js.br exists and there is no uncompressed Foo.js next to it, the generated endpoint gets Content-Type: text/javascript but no Content-Encoding: br. If both files are present the br header is emitted correctly.

  5. added
    Needs: Author Feedback
    and removed on Sep 2, 2026
  6. dotnet-policy-service commented on Sep 2, 2026

    @dotnet-policy-service
    Contributor

    Hi @jonganej. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

  7. dotnet-policy-service commented on Sep 25, 2026

    @dotnet-policy-service
    Contributor

    This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

    See our Issue Management Policies for more information.

  8. removed this from the Backlog milestone on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackStatus: No Recent Activityarea-blazor

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions