uid |
---|
UnoWasmBootstrap.Features.PreCompression |
Pre-compression has two modes:
- In-place, where Brotli compressed files are placed next to original files
- Legacy, where a
web.config
file url rewriter rule is used
The parameters for the pre-compression are as follows:
WasmShellGenerateCompressedFiles
which can betrue
orfalse
. This property is ignored when buildingMonoRuntimeDebuggerEnabled
is set totrue
, andtrue
by default when theConfiguration
property is set toRelease
WasmShellCompressedExtension
is an item group which specifies which files to compress. By default, thewasm
,clr
,js
,json
,css
,html
,dat
,ttf
, andtxt
files are pre-compressed. More files can be added as follows:
<ItemGroup>
<WasmShellCompressedExtension Include=".db"/>
</ItemGroup>
WasmShellBrotliCompressionQuality
which controls the compression quality used to pre-compress the files. Possible values are in the range from0
to11
. The default value is7
.
Warning
Two-digit compression quality values (10
and higher) are intended for extra-intensive CPU usage and can significantly slow down build time.
WasmShellCompressionLayoutMode
which can be set toInPlace
orLegacy
. If not set and for backward compatility reasons,Legacy
is automatically selected if aweb.config
file is detected in the layout, and contains the_compressed_br
string.
This mode is to be preferred for web servers that support accept-encoding
header file rewriting. In the case of Azure Static WebApps, if a file next to the original one is suffixed with .br
, and the client requested for brotli compressed files, the in-place compressed file will be served.
Note
To achieve the same behavior in a standalone ASP.NET Core application the CompressedStaticFiles third-party library can be used.
The IIS compression support has too many knobs for the size of generated WebAssembly files, which makes the serving of static files inefficient.
The Bootstrapper tooling will generate two folders _compressed_gz
and _compressed_br
which contain compressed versions of the main files. A set IIS rewriting rules are used to redirect the queries to the requested pre-compressed files, with a preference for Brotli.
When building an application, place the following file in the wwwroot
folder to automatically enable the use of pre-compressed files.
Note that the pre-compressed files are optional, and if the rewriting rules are removed or not used (because the site is served without IIS), the original files are available at their normal locations.