Why is blazor loading additional files when loading a page from a class library

Viewed 389

Problem:

When I open a blazor page from a class library (PWA enabled, ASP.NET core hosted, Configure for HTTPS), it contacts the server again. My desired/expected behaviour would be that it treats this page just like the pages included in the original client library.

Setup:

I have an empty blazor project (webassembly) and an additional Razor component class library.

I've changed the target framework of the class library to netstandard2.1 and altered the package references. It now looks like this:

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

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <RazorLangVersion>3.0</RazorLangVersion>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.5" />
    <PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
  </ItemGroup>

</Project>

I've reference the class library in the App.Razor as follows:

<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(SomeMicroservice.Client.Component1).Assembly }">
... standard generated found/not found code ...
</Router>

What works:

The page loads as expected (it shows static content)

What doesn't work:

When the browser goes into offline mode, the page cannot be loaded because it has to download items from the server. Other pages (included in the base client project) can be loaded offline (PWA isn't the issue here).

Everytime the page is visited the loading page appears (same issue, it has to download stuff)

Question:

Is it possible (if so, how?) to treat the page from the new class library as a page form the original class library? No downloads/loads, so that is works with PWA?

1 Answers

When the URL is altered, blazor will re-download all the files (giving you the 'loading...' page). I'm not sure why it does this, but for a normal flow (using links in the app/html) this isn't a problem as it won't do it then.

When adding a link to the menu page, the external page is loaded without any additional downloads.

When the url is changed, for a page outside the original client project or another page from outside the original client project, the 'loading...' page will be shown and the files will be re-downloaded.

tl;dr: I added a link instead of altering the url and it works

Edit: Fixed spelling

Related