Skip to content

Commit c9d6cb9

Browse files
authored
Enhance Blazor WASM Brotli content (#17958)
1 parent dad2a60 commit c9d6cb9

2 files changed

Lines changed: 111 additions & 2 deletions

File tree

aspnetcore/host-and-deploy/blazor/webassembly.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ description: Learn how to host and deploy a Blazor app using ASP.NET Core, Conte
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/16/2020
8+
ms.date: 04/22/2020
99
no-loc: [Blazor, SignalR]
1010
uid: host-and-deploy/blazor/webassembly
1111
---
1212
# Host and deploy ASP.NET Core Blazor WebAssembly
1313

14-
By [Luke Latham](https://github.com/guardrex), [Rainer Stropek](https://www.timecockpit.com), and [Daniel Roth](https://github.com/danroth27)
14+
By [Luke Latham](https://github.com/guardrex), [Rainer Stropek](https://www.timecockpit.com), [Daniel Roth](https://github.com/danroth27), and [Ben Adams](https://twitter.com/ben_a_adams).
1515

1616
[!INCLUDE[](~/includes/blazorwasm-preview-notice.md)]
1717

@@ -29,6 +29,8 @@ The following deployment strategies are supported:
2929

3030
When a Blazor WebAssembly app is published, the output is precompressed using the [Brotli compression algorithm](https://tools.ietf.org/html/rfc7932) at the highest level to reduce the app size and remove the need for runtime compression.
3131

32+
For IIS *web.config* compression configuration, see the [IIS: Brotli and Gzip compression](#brotli-and-gzip-compression) section.
33+
3234
## Rewrite URLs for correct routing
3335

3436
Routing requests for page components in a Blazor WebAssembly app isn't as straightforward as routing requests in a Blazor Server, hosted app. Consider a Blazor WebAssembly app with two components:
@@ -152,6 +154,10 @@ If a standalone app is hosted as an IIS sub-app, perform either of the following
152154

153155
Removing the handler or disabling inheritance is performed in addition to [configuring the app's base path](xref:host-and-deploy/blazor/index#app-base-path). Set the app base path in the app's *index.html* file to the IIS alias used when configuring the sub-app in IIS.
154156

157+
#### Brotli and Gzip compression
158+
159+
IIS can be configured via *web.config* to serve Brotli or Gzip compressed Blazor assets. For an example configuration, see [web.config](webassembly/_samples/web.config?raw=true).
160+
155161
#### Troubleshooting
156162

157163
If a *500 - Internal Server Error* is received and IIS Manager throws errors when attempting to access the website's configuration, confirm that the URL Rewrite Module is installed. When the module isn't installed, the *web.config* file can't be parsed by IIS. This prevents the IIS Manager from loading the website's configuration and the website from serving Blazor's static files.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<system.webServer>
4+
<staticContent>
5+
<remove fileExtension=".dll" />
6+
<remove fileExtension=".json" />
7+
<remove fileExtension=".wasm" />
8+
<remove fileExtension=".woff" />
9+
<remove fileExtension=".woff2" />
10+
<remove fileExtension=".js.gz" />
11+
<remove fileExtension=".dll.gz" />
12+
<remove fileExtension=".json.gz" />
13+
<remove fileExtension=".wasm.gz" />
14+
<remove fileExtension=".js.br" />
15+
<remove fileExtension=".dll.br" />
16+
<remove fileExtension=".json.br" />
17+
<remove fileExtension=".wasm.br" />
18+
<mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
19+
<mimeMap fileExtension=".json" mimeType="application/json" />
20+
<mimeMap fileExtension=".wasm" mimeType="application/wasm" />
21+
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
22+
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
23+
<mimeMap fileExtension=".js.gz" mimeType="application/javascript" />
24+
<mimeMap fileExtension=".dll.gz" mimeType="application/octet-stream" />
25+
<mimeMap fileExtension=".json.gz" mimeType="application/json" />
26+
<mimeMap fileExtension=".wasm.gz" mimeType="application/wasm" />
27+
<mimeMap fileExtension=".js.br" mimeType="application/javascript" />
28+
<mimeMap fileExtension=".dll.br" mimeType="application/octet-stream" />
29+
<mimeMap fileExtension=".json.br" mimeType="application/json" />
30+
<mimeMap fileExtension=".wasm.br" mimeType="application/wasm" />
31+
</staticContent>
32+
<httpCompression>
33+
<dynamicTypes>
34+
<remove mimeType="application/javascript" />
35+
<remove mimeType="application/json" />
36+
<remove mimeType="application/octet-stream" />
37+
<remove mimeType="application/wasm" />
38+
</dynamicTypes>
39+
<staticTypes>
40+
<remove mimeType="application/javascript" />
41+
<remove mimeType="application/json" />
42+
<remove mimeType="application/octet-stream" />
43+
<remove mimeType="application/wasm" />
44+
</staticTypes>
45+
</httpCompression>
46+
<rewrite>
47+
<outboundRules rewriteBeforeCache="true">
48+
<rule name="Add Vary Accept-Encoding" preCondition="PreCompressedFile" enabled="true">
49+
<match serverVariable="RESPONSE_Vary" pattern=".*" />
50+
<action type="Rewrite" value="Accept-Encoding" />
51+
</rule>
52+
<rule name="Add Encoding Brotli" preCondition="PreCompressedBrotli" enabled="true" stopProcessing="true">
53+
<match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
54+
<action type="Rewrite" value="br" />
55+
</rule>
56+
<rule name="Add Encoding Gzip" preCondition="PreCompressedGzip" enabled="true" stopProcessing="true">
57+
<match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
58+
<action type="Rewrite" value="gzip" />
59+
</rule>
60+
<preConditions>
61+
<preCondition name="PreCompressedFile">
62+
<add input="{HTTP_URL}" pattern="\.(gz|br)$" />
63+
</preCondition>
64+
<preCondition name="PreCompressedGzip">
65+
<add input="{HTTP_URL}" pattern="\.gz$" />
66+
</preCondition>
67+
<preCondition name="PreCompressedBrotli">
68+
<add input="{HTTP_URL}" pattern="\.br$" />
69+
</preCondition>
70+
</preConditions>
71+
</outboundRules>
72+
<rules>
73+
<rule name="Serve subdir">
74+
<match url=".*" />
75+
<action type="Rewrite" url="wwwroot\{R:0}" />
76+
</rule>
77+
<rule name="Rewrite brotli file" stopProcessing="true">
78+
<match url="(.*)"/>
79+
<conditions>
80+
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />
81+
<add input="{REQUEST_FILENAME}.br" matchType="IsFile" />
82+
</conditions>
83+
<action type="Rewrite" url="{R:1}.br" />
84+
</rule>
85+
<rule name="Rewrite gzip file" stopProcessing="true">
86+
<match url="(.*)"/>
87+
<conditions>
88+
<add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" />
89+
<add input="{REQUEST_FILENAME}.gz" matchType="IsFile" />
90+
</conditions>
91+
<action type="Rewrite" url="{R:1}.gz" />
92+
</rule>
93+
<rule name="SPA fallback routing" stopProcessing="true">
94+
<match url=".*" />
95+
<conditions logicalGrouping="MatchAll">
96+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
97+
</conditions>
98+
<action type="Rewrite" url="wwwroot\" />
99+
</rule>
100+
</rules>
101+
</rewrite>
102+
</system.webServer>
103+
</configuration>

0 commit comments

Comments
 (0)