Skip to content

Blazor WASM: Javascript/css not compressing when using Brotli web.config #51166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Schoof-T opened this issue Oct 5, 2023 · 6 comments
Closed
1 task done
Assignees
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Pillar: Technical Debt Status: Resolved

Comments

@Schoof-T
Copy link

Schoof-T commented Oct 5, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When hosting a Blazor WASM application, I want to use brotli compression for the best compression possible. However when using the Microsoft suggested web.config (https://raw.githubusercontent.com/dotnet/AspNetCore.Docs/main/aspnetcore/blazor/host-and-deploy/webassembly/_samples/web.config) mine/external libraries their javascript/css files are not longer compressed.

image

When using the default generated web.config, the .js and .css files are compressed.

image

My IIS has the following installed and enabled:

Expected Behavior

I would expect the .js and .css files to also be compressed, preferebly in brotli or otherwise in gzip.

Steps To Reproduce

Exceptions (if any)

No response

.NET Version

.NET 7

Anything else?

A secondary question, is it possible to generate the brotli web.config when running dotnet publish? Is this the correct way to do this? https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-7.0

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Oct 5, 2023
@javiercn
Copy link
Member

javiercn commented Oct 5, 2023

@Schoof-T thanks for contacting us.

I don't think the web.config applies to files that are not part of the blazor payload. That is, during publish we will compress the Blazor runtime and related files, but we won't be compressing any other static file that you add/bring.

The configuration in the web.config requires the file to have been statically compressed to serve a compressed version. You can tweak the web.config to compress all the files or to enable dynamic compression on the ones that are not statically compressed, but that's something that we can't offer guidance on.

@mkArtakMSFT mkArtakMSFT added the Docs This issue tracks updating documentation label Oct 5, 2023
@mkArtakMSFT mkArtakMSFT added this to the 8.0.0 milestone Oct 5, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: 8.0.0, .NET 9 Planning Oct 5, 2023
@ghost
Copy link

ghost commented Oct 5, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@Schoof-T
Copy link
Author

Schoof-T commented Oct 5, 2023

@Schoof-T thanks for contacting us.

I don't think the web.config applies to files that are not part of the blazor payload. That is, during publish we will compress the Blazor runtime and related files, but we won't be compressing any other static file that you add/bring.

The configuration in the web.config requires the file to have been statically compressed to serve a compressed version. You can tweak the web.config to compress all the files or to enable dynamic compression on the ones that are not statically compressed, but that's something that we can't offer guidance on.

Thank you for the reply, that makes sense. Is there a reason why you are not compressing other files that I'm adding? I feel like that's a great way to optimize the size of a Blazor App. Might also be a good idea to add this information to the docs, because now just enabling the Brotli web.config has actually increased the file size of my Blazor App.

I'm having a difficult time finding guidance on how to optimize the the files I added in combination with the brotli compression.

@Schoof-T
Copy link
Author

Schoof-T commented Oct 6, 2023

I have started noticing even stranger things now. I managed to get the brotli compression working with the default generated web.config (I didn't retry the default web.config after installing IIS Compression)

I publish with dotnet publish --configuration Release --self-contained true --runtime win-x64.
But the file size of the some dll's are larger than with the microsoft provided web.config.

Auto generated web.config
image
Microsoft provided web.config
image

The web.config that gets auto generated for me is the following:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".blat" />
      <remove fileExtension=".dat" />
      <remove fileExtension=".dll" />
      <remove fileExtension=".json" />
      <remove fileExtension=".wasm" />
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".blat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".wasm" mimeType="application/wasm" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
    </staticContent>
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/octet-stream" enabled="true" />
        <add mimeType="application/wasm" enabled="true" />
      </dynamicTypes>
    </httpCompression>
    <rewrite>
      <rules>
        <rule name="Serve subdir">
          <match url=".*" />
          <action type="Rewrite" url="wwwroot\{R:0}" />
        </rule>
        <rule name="SPA fallback routing" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="wwwroot\" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

The .br files are all available after the publish. But IIS is still doing something different.
image

@ghost
Copy link

ghost commented Dec 18, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed Docs This issue tracks updating documentation labels Dec 18, 2023
@mkArtakMSFT
Copy link
Contributor

Closing as a dupe of #52824

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2023
@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Dec 18, 2023
@ghost ghost added the Status: Resolved label Dec 18, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Pillar: Technical Debt Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants