Deploying Blazor WASM with caching dependencies

219 views Asked by At

I'm trying to deploy my AOT-compiled Blazor WASM app as static resources served by a normal Asp.NET server. This works. but I'm facing two issues with this.

  1. The output seems unreasonably large. e.g _framework/dotnet.wasm is a whopping 87mB. Is this expected?

  2. _framework/dotnet.wasm is not cached in the browser, resulting in a full download each visit/refresh.

I have configured the server to serve static content with cache headers set. I can see the cache headers on the request in the browser.

Accept-Ranges: bytes
Cache-Control: public, max-age=2592000
Connection: keep-alive
Content-Length: 48154724
Content-Type: application/wasm
Date: Tue, 17 Jan 2023 18:34:58 GMT
ETag: "1d92a9280cc0c64"
Last-Modified: Tue, 17 Jan 2023 16:41:12 GMT

The static file settings looks like so:

app.UseStaticFiles(new StaticFileOptions()
{
    ServeUnknownFileTypes = true, //serve the framework files

    HttpsCompression = Microsoft.AspNetCore.Http.Features.HttpsCompressionMode.Compress,
    OnPrepareResponse = (context) =>
    {
        var headers = context.Context.Response.GetTypedHeaders();
        headers.CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue
        {
            Public = true,
            MaxAge = TimeSpan.FromDays(30)
        };
    }
});

For the Blazor WASM site, the following settings are used:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <RootNamespace>TraceLens.Site</RootNamespace>
        <RunAOTCompilation>true</RunAOTCompilation>
        <BlazorCacheBootResources>true</BlazorCacheBootResources>
        <BlazorEnableCompression>true</BlazorEnableCompression>
    </PropertyGroup>

TLDR:

dotnet.wasm is 87 MB, it takes 12 seconds to download, and it's not cached. Any pointers are very welcome. I'm not sure where to begin or what to ask here

The actual site can be found here: (it does start after the 12ish seconds)

http://traceview.ornell.io/logs?traceId=629FA6A4B6873921F600F59DFD0A4539&search=

0

There are 0 answers