Skip to content

Conversation

@javiercn
Copy link
Member

@javiercn javiercn commented May 29, 2024

Adds support for fingerprinting assets

  • Fingerprinting works by defining expressions on the RelativePath of assets.
  • Expressions contain tokens like [.{fingerprint}] which allow us to define replacements that need to happen as part of the build.
  • Expressions might result in more than one endpoint if they are marked as optional with either ? or !. These modifiers determine how the file is addressable in standalone scenarios.
    • ? signifies that the file will not have its name replaced to add the expression.
    • ! signifies that the file will have its name replaced to add the expression.
  • Expressions can contain embedded values via {.fingerprint=value} syntax, which makes it so that value takes precedence when reducing the expression to its literal form.
  • The expressions are retained through the build until the last moment when we replace them with values to produce the final path/routes. This allows us to refer to assets/endpoints logically through the build.
  • Any endpoint with a replaced value on its route, gets assigned a 'label' in its properties as well as the values that were replaced on the expression used to define that endpoint.
    • The label is the endpoint path without any token expression.
    • The replaced values are the list of values that were applied to the route.
    • The combination of label + values allows the endpoint to be uniquely identified with a human-addressable name.

Scoped CSS

  • Scoped CSS asset project bundles are updated to fingerprint the file and offer the non-fingerprinted endpoint with [.{fingerprint}]!.bundle.scp.css
  • Scoped CSS app bundles are updated to offer a fingerprinted endpoint with [.{fingerprint}.styles.css
  • ConcatenateCss is updated to rely on endpoints.
  • Three new tasks help working with endpoints.
    • FilterStaticWebAssetEndpoints to filter a list of endpoints based on a configurable set of criteria.
    • UpdateStaticWebAssetEndpoints to modify a header, property, or selector of a group of endpoints. Options are RemoveAll, Remove, Append, Replace.
    • ResolveEndpointRoutes to produce the final URL that can be used on Tasks that need to consume the endpoint path

Other assets

  • Other assets are "soft fingerprinted" by appending the fingerprint after the last extension. The file will be served as fingerprinted, but won't be fingerprinted on disk.

@ghost ghost added Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member labels May 29, 2024
@javiercn javiercn marked this pull request as ready for review June 4, 2024 22:10
@javiercn javiercn requested review from a team as code owners June 4, 2024 22:10
Copy link
Member

@MackinnonBuck MackinnonBuck left a comment

Choose a reason for hiding this comment

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

This is looking great to me. Mostly minor suggestions/questions.

@javiercn javiercn force-pushed the javiercn/static-web-asset-endpoints-fingerprints-all-assets branch 3 times, most recently from 2a67421 to 35e4615 Compare June 6, 2024 19:49
* Cache immutable max-age=31536000 (1 year)
* Cache media (images, videos, audio) max-age=3600 (1 hour)
* Make caching configurable per content type
@javiercn javiercn force-pushed the javiercn/static-web-asset-endpoints-fingerprints-all-assets branch from 35e4615 to 830517f Compare June 7, 2024 00:02
@javiercn javiercn enabled auto-merge (squash) June 7, 2024 06:22
@javiercn javiercn merged commit fd6042c into main Jun 7, 2024
@javiercn javiercn deleted the javiercn/static-web-asset-endpoints-fingerprints-all-assets branch June 7, 2024 07:59
spadapet added a commit to dotnet/maui that referenced this pull request Feb 22, 2025
… bundles (#27788)

### Description of Change

This is for MAUI Blazor Hybrid apps. CSS Hot Reload from Visual Studio
wasn't working for scoped CSS files that come from Razor Class
Libraries.

During the build, the scoped CSS files get built into a bundle called:
* `LibraryName.<fingerprint>.bundle.scp.css`

At runtime, CSS Hot Reload will trigger a scoped CSS build, which
outputs:
* `LibraryName.bundle.scp.css`

Fingerprints are not included during that part of the build. This fix
will match the original fingerprinted name to the newly built name and
allows CSS hot reload to work.

This was the PR that introduced fingerprinting:
* dotnet/sdk#41244

### Issues Fixed

* [Bug
2272902](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2272902):
[MAUI][Hot Reload] The web page doesn't apply the changes in
RazorClassLibrary\xx.razor.css file after referencing RazorClassLibrary
App from MAUI Blazor App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants