Skip to content

[Blazor] Failed to find a valid digest in the 'integrity' attribute for resource - because is picking up the http cached version #31467

Closed
@3x0dv5

Description

@3x0dv5

Just to leave here a note on something I came across while trying to figure out what was going on.

If for some reason you removed the service worker from your app resulting on the resources being actually cached in the common http cache, there is a possibility that once you update your app and re-enable the service worker you will get this error, because the service worker will pick up the http cached version and not the server's.

What I did was to add cache: "no-cache" to the Request's init.

So my onInstall now looks something like this

async function onInstall(event) {
    console.info('Service worker: Install');

    // Fetch and cache all matching items from the assets manifest
    const assetsRequests = self.assetsManifest.assets
        .filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url)))
        .filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url)))
        .map(asset => new Request(asset.url, { integrity: asset.hash, cache: "no-cache" }));
    
    // Also cache authentication configuration
    assetsRequests.push(new Request('_configuration/TestApp.Client'));

    await caches.open(cacheName).then(cache => cache.addAll(assetsRequests));
}

Not sure if it is the best way given that this is not what the default project's template brings.
If this is a good way, could we get the default project's template updated (Blazor WebAssembly App blazorwasm)?

Had my head pretty scratched trying to figure out what was going on. In particular because I had the bad idea of re-enabling the service worker at the same time I migrated the application to Linux/Nginx and updated a few libraries, so I was left chasing my own tail. My build machine is Windows but this new server is Linux and the end line of this file is indeed the \r\n, but had nothing to so with it, it was indeed that I deployed an updated version of a RCL that has an updated CSS file but the problem was that old one version of this CSS was still in the http cache from when the PWA stuff was disabled.

Metadata

Metadata

Assignees

Labels

✔️ Resolution: FixedThe bug or enhancement requested in this issue has been checked-in!area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-boot-upfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions