-
Notifications
You must be signed in to change notification settings - Fork 10k
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
[Blazor] Adds compresion support for all assets in an application #55558
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javiercn
force-pushed
the
javiercn/add-static-web-assets-endpoints
branch
from
May 7, 2024 14:25
a549ca3
to
8a5baa6
Compare
javiercn
changed the title
[Blazor] Adds static asset endpoints, serve compressed assets
[Blazor] Adds compresion support for all assets in an application
May 9, 2024
javiercn
requested review from
captainsafia,
a team,
BrennanConroy,
halter73 and
wtgodbe
as code owners
May 9, 2024 16:51
javiercn
removed request for
a team,
halter73,
captainsafia,
BrennanConroy and
wtgodbe
May 9, 2024 16:52
javiercn
force-pushed
the
javiercn/add-static-web-assets-endpoints
branch
2 times, most recently
from
May 10, 2024 10:58
96464a8
to
f91ac86
Compare
MackinnonBuck
approved these changes
May 10, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
I left some questions and comments but they're nothing worth blocking the PR on.
src/Components/Endpoints/src/Builder/ComponentEndpointConventionBuilderHelper.cs
Show resolved
Hide resolved
...omponents/WebAssembly/Samples/HostedBlazorWebassemblyApp/Server/appsettings.Development.json
Outdated
Show resolved
Hide resolved
...Assembly/Server/src/Builder/WebAssemblyRazorComponentsEndpointConventionBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
...bAssembly/Server/src/ComponentsWebAssemblyStaticAssetsEndpointConventionBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/StaticAssets/src/StaticAssetsEndpointRouteBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/StaticAssets/src/StaticAssetsEndpointRouteBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/StaticAssets/src/StaticAssetsEndpointRouteBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
javiercn
force-pushed
the
javiercn/add-static-web-assets-endpoints
branch
2 times, most recently
from
May 13, 2024 13:49
7d420fa
to
51b19d0
Compare
javiercn
force-pushed
the
javiercn/add-static-web-assets-endpoints
branch
from
May 13, 2024 13:54
51b19d0
to
f89d513
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR adds a new
MapStaticAssetEndpoints
routerware that reads a manifest generated at build / publish time and maps the endpoints defined in the manifest to the files in the application wwwroot folder.This PR adds a MatcherPolicy to perform content negotiation based on the Accept-Encoding header. Compressed resources contain a
ContentEncoding
attribute in their metadata that is used to filter out the compressed asset to serve to the client based on the Accept-Encoding header.The content encoding has an associated
Quality
value that represents the 'server preference' for the encoding. We always use the client preference and only rely on the server preference to break ties.This process is completely driven by de the build and transparent to the runtime, if in the future we add support for zstd, sbr, etc. we don't need to change the runtime.
The logic for serving static files is borrowed from the static files middleware, with simplifications and additions. I've ported the relevant tests to ensure a high degree of compatibility.
The logic is new "routerware" instead of directly baked into the static files middleware because we do not want to pollute that middleware with more complex logic and we are going to be layering fingerprinting on top of this change, which will register more endpoints that will include more custom headers, which is not suitable for the static files middleware.
During development we wrap the endpoints we generate to support changing the files while the app is running (we recompute some of the values on the fly and also register a fallback route that matches file patterns to serve new files added while the app is running).
The build/publish process computes all the required information about the assets that is used to emit the response. The ETag and Last-Modified values are computed using the Base64(SHA256) hash of the content and the LastWrite on the file at build/publish time.