Skip to content

Static web assets from a NuGet package are not compressed on their fingerprinted route (project references are) #56648

Open

Description

@bes3020

Describe the bug

When a Razor class library is consumed as a NuGet package, its static web assets get compressed (.gz / .br) endpoints only on their plain route. The fingerprinted route, which is what @Assets["..."] returns, has no Content-Encoding selectors, so MapStaticAssets always serves it uncompressed.

The same library consumed as a project reference gets both compressed variants on the fingerprinted route, as expected.

So with a package reference, following the template guidance (@Assets[...] + MapStaticAssets) for a library stylesheet makes it larger on the wire than linking it by its plain path. In our app, a 429 KB library stylesheet went out raw under its fingerprinted name and as 63 KB of Brotli under its plain name.

The SDK-generated @import of a package's <Lib>.<fp>.bundle.scp.css in the app's scoped CSS bundle is affected in the same way, and an app cannot work around that one.

This may share a root cause with #54907.

To reproduce (SDK 10.0.100, Linux)

dotnet new razorclasslib -n DemoLib -o DemoLib
mkdir -p DemoLib/wwwroot/css
python3 -c "print('.demo{color:red}\n'*4000)" > DemoLib/wwwroot/css/demo.css
dotnet pack DemoLib -c Release -o feed -p:Version=1.0.0

dotnet new blazor -n DemoApp -o DemoApp --interactivity Server --empty
# nuget.config in DemoApp pointing at ./feed, then:
dotnet add DemoApp package DemoLib --version 1.0.0
dotnet publish DemoApp -c Release -o pub

Then list the endpoints for demo in pub/DemoApp.staticwebassets.endpoints.json (Route | AssetFile | Content-Encoding selector).

Package reference:

_content/DemoLib/css/demo.0q6p3fhpob.css | _content/DemoLib/css/demo.css     | []
_content/DemoLib/css/demo.css            | _content/DemoLib/css/demo.css     | []
_content/DemoLib/css/demo.css            | _content/DemoLib/css/demo.css.gz  | ['gzip']
_content/DemoLib/css/demo.css            | _content/DemoLib/css/demo.css.br  | ['br']
_content/DemoLib/css/demo.css.br         | _content/DemoLib/css/demo.css.br  | []
_content/DemoLib/css/demo.css.gz         | _content/DemoLib/css/demo.css.gz  | []

Project reference (dotnet add DemoApp reference DemoLib/DemoLib.csproj instead):

_content/DemoLib/css/demo.0q6p3fhpob.css    | _content/DemoLib/css/demo.css.gz | ['gzip']
_content/DemoLib/css/demo.0q6p3fhpob.css    | _content/DemoLib/css/demo.css.br | ['br']
_content/DemoLib/css/demo.0q6p3fhpob.css    | _content/DemoLib/css/demo.css    | []
_content/DemoLib/css/demo.0q6p3fhpob.css.br | _content/DemoLib/css/demo.css.br | []
_content/DemoLib/css/demo.0q6p3fhpob.css.gz | _content/DemoLib/css/demo.css.gz | []
_content/DemoLib/css/demo.css               | ... (same as above, plain route)

Expected behavior

A package asset's fingerprinted route gets the same gzip / br endpoints as a project-reference asset, so @Assets[...] and the scoped bundle @import are served compressed.

Notes

This looks like it's because a package asset's relative path carries no #[.{fingerprint}] pattern, so the compressed asset's path (css/demo.css.gz) never produces a fingerprinted compressed endpoint for compression negotiation to attach to. None of the switches in Microsoft.NET.Sdk.StaticWebAssets.Compression.targets change this; they only choose which assets and formats are compressed.

Activity

  1. added
    untriaged
    on Oct 14, 2026
  2. locked and limited conversation to collaborators on Oct 14, 2026
  3. unlocked this conversation on Oct 14, 2026
  4. github-actions commented on Oct 14, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    • 🏷️ Labels: Area-StaticWebAssets Bug
    • 💻 Assignment: @javiercn | @dotnet/aspnet-blazor-eng
    • 🟩 Confidence: high - Issue directly concerns Static Web Assets compression endpoints, and the CODEOWNERS section is unambiguous.

    Similar issues: #54907 (potentially related)

    ➡️ Summary: Package-consumed static web assets lack gzip/br endpoints on their fingerprinted route, unlike project references, so @Assets[...] serves uncompressed content. Investigate how package asset endpoints are generated for compression.

    Generated by 🏷️ Issue Triage for #56648 · copilot · auto · 17.6 AIC · ⌖ 0.676 AIC · ⊞ 14.3K · ◷

  5. removed
    untriaged
    on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions