-
Notifications
You must be signed in to change notification settings - Fork 25.1k
[Pre3] Blazor WASM fingerprinting and environment property #35057
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
Changes from 14 commits
57bde60
2986615
7ff2e12
54f16d3
88c0a22
b1656b3
9e82848
b7246ad
086c255
7d2fd7f
24ff1d1
e0e8f1f
f662d7f
7eab3e9
b5aee1c
517a64a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,4 +132,74 @@ Also make this change in the *Routing* article at Line 1633. | |
|
||
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
|
||
### Client-side fingerprinting | ||
|
||
Last year, the release of .NET 9 introduced [server-side fingerprinting](https://en.wikipedia.org/wiki/Fingerprint_(computing)) of static assets in Blazor Web Apps with the introduction of [Map Static Assets routing endpoint conventions (`MapStaticAssets`)](xref:fundamentals/map-static-files), the [`ImportMap` component](xref:blazor/fundamentals/static-files#importmap-component), and the <xref:Microsoft.AspNetCore.Components.ComponentBase.Assets?displayProperty=nameWithType> property (`@Assets["..."]`) to resolve fingerprinted JavaScript modules. For .NET 10, you can opt-into client-side fingerprinting of JavaScript modules for standalone Blazor WebAssembly apps. | ||
|
||
In standalone Blazor WebAssembly apps during build/publish, the framework overrides placeholders in `index.html` with values computed during build to fingerprint static assets. A fingerprint is placed into the `blazor.webassembly.js` script file name. | ||
|
||
The following changes must be made in the `wwwwoot/index.html` file to adopt the fingerprinting feature. The standalone Blazor WebAssembly project template will be updated to include these changes in an upcoming preview release: | ||
|
||
```diff | ||
<head> | ||
... | ||
+ <script type="importmap"></script> | ||
</head> | ||
|
||
<body> | ||
... | ||
- <script src="_framework/blazor.webassembly.js"></script> | ||
+ <script src="_framework/blazor.webassembly#[.{fingerprint}].js"></script> | ||
</body> | ||
|
||
</html> | ||
``` | ||
|
||
In the project file (`.csproj`), add the `<OverrideHtmlAssetPlaceholders>` property set to `true`: | ||
|
||
```diff | ||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net10.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
+ <OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders> | ||
</PropertyGroup> | ||
</Project> | ||
``` | ||
|
||
To fingerprint additional JS modules in standalone Blazor WebAssembly apps, use the `<StaticWebAssetFingerprintPattern>` property in the app's project file (`.csproj`). | ||
|
||
In the following example, a fingerprint is added for all developer-supplied `.mjs` files in the app: | ||
|
||
```xml | ||
<StaticWebAssetFingerprintPattern Include="JSModule" Pattern="*.mjs" | ||
Expression="#[.{fingerprint}]!" /> | ||
``` | ||
|
||
The files are automatically placed into the import map: | ||
|
||
* Automatically for Blazor Web App CSR. | ||
* When opting-into module fingerprinting in standalone Blazor WebAssembly apps per the preceding instructions. | ||
|
||
When resolving the import for JavaScript interop, the import map is used by the browser resolve fingerprinted files. | ||
|
||
### Set the environment in standalone Blazor WebAssembly apps | ||
|
||
The `Properties/launchSettings.json` file is no longer used to control the environment in standalone Blazor WebAssembly apps. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maraf This makes it sound like we made a breaking change here. Is the only impact on how you set the environment for standalone Blazor WebAssembly apps during development? Or is there also impact on existing ASP.NET Core hosted apps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only standalone mode during development affected |
||
|
||
Starting in .NET 10, set the environment with the `<WasmApplicationEnvironmentName>` property in the app's project file (`.csproj`). | ||
|
||
The following example sets the app's environment to `Staging`: | ||
|
||
```xml | ||
<WasmApplicationEnvironmentName>Staging</WasmApplicationEnvironmentName> | ||
``` | ||
|
||
As usual, the default environments are: | ||
guardrex marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* `Development` for build. | ||
* `Production` for publish. | ||
|
||
--> |
Uh oh!
There was an error while loading. Please reload this page.