Slide 1

Slide 1 text

Blazor WebAssembly: Neues in .NET 5 Sanfte Evolution Christian Weyer https://thinktecture.com/christian-weyer @christianweyer Co-Founder & CTO

Slide 2

Slide 2 text

2 § Co-Founder & CTO at Thinktecture AG § Personal focus on § Mobile & web-based application architectures § Interoperability, cross-device § Pragmatic end-to-end solutions § Cloud-native & serverless architectures § Independent Microsoft Regional Director § Microsoft MVP for Developer Technologies & Azure ASPInsider, AzureInsider § Google GDE for Web Technologies, Angular [email protected] @christianweyer https://www.thinktecture.com Blazor WebAssembly Neues in .NET 5 Christian Weyer

Slide 3

Slide 3 text

3 Blazor WebAssembly Neues in .NET 5 Introduction to Blazor WebAssembly https://www.thinktecture.com/de/blazor/webinar-aspnet-blazor-webassembly/

Slide 4

Slide 4 text

4 § Migration § Developer Tooling § Runtime Performance § Component Enhancements § (something new for you &) Q&A Blazor WebAssembly Neues in .NET 5 Talking Points

Slide 5

Slide 5 text

5 § Blazor WASM 3.2 in .NET Core 3.1 is OK-ish… § A typical “v1” § Ongoing improvements with interim releases § Lots of people were waiting for .NET 5 § Blazor in .NET 5 is more of an evolution § https://docs.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore- 5.0?view=aspnetcore-5.0#blazor § More ongoing improvements with interim releases § Blazor WASM evolution process feels like Angular 2+ Blazor WebAssembly Neues in .NET 5 Blazor WASM is still young

Slide 6

Slide 6 text

6 Performance improvements Debugging improvements CSS isolation Microsoft Identity v2.0 and MSAL v2.0 New InputFile component WASM prerendering New InputRadio and InputRadioGroup components Trimming/linking improvements Component virtualization Browser compatibility analyzer ontoggle event support Lazy load assemblies Set UI focus in Blazor apps Updated globalization support Custom validation class attributes Form components support display name IAsyncDisposable support Catch-all route parameters JavaScript isolation and object references Blazor WebAssembly Neues in .NET 5 Overview of new features in .NET 5 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅

Slide 7

Slide 7 text

7 Blazor WebAssembly Neues in .NET 5 Migration

Slide 8

Slide 8 text

8 § Compatibility: Few breaking changes § Changes to .csproj file § Update SDK from Microsoft.NET.Sdk.Web to Microsoft.NET.Sdk.BlazorWebAssembly § Set TargetFramework to net5.0 net5.0 § If present: remove package reference to Microsoft.AspNetCore.Components.WebAssembly.Build § Update Nuget references to 5.0.0 § Clean & rebuild § Changes to app § index.html: App element is a div now
Loading...
§ Startup.cs: builder.RootComponents.Add("#app"); Blazor WebAssembly Neues in .NET 5 Moving from .NET Core 3.1 to .NET 5

Slide 9

Slide 9 text

9 Blazor WebAssembly Neues in .NET 5 Developer Tooling

Slide 10

Slide 10 text

10 § Blazor WASM still shallow on developer tooling § Debugging improvements in .NET 5 § Still no fully-fledged debugger, both in browsers, and in VS § Browser compatibility analyzer § Warns developer when app uses unsupported APIs § Basic reload support in .NET 5 and VS 2019 16.8 § Full live reload currently with external tools, like LiveSharp § Uses external dev server instance via command line § Commercial tool Blazor WebAssembly Neues in .NET 5 SPA developer tooling

Slide 11

Slide 11 text

11 § Blazor WASM performs IL trimming to reduce size of published output § Trimming may have detrimental effects § Apps using reflection or similar dynamic features may break § Options can be configured § Trimming for Blazor WASM apps is enabled by default § Trimming can be disabled by setting the PublishTrimmed MSBuild property to false in the .csproj file Blazor WebAssembly Neues in .NET 5 App trimming: Make .NET deployments smaller

Slide 12

Slide 12 text

12 Blazor WebAssembly Neues in .NET 5 Runtime Performance

Slide 13

Slide 13 text

13 § Blazor WASM still uses a .NET IL interpreter § Internal optimizations in UI rendering and JSON handling § Optimization in the .NET IL interpreter § Optimizations in core framework libraries § String comparisons, dictionary lookups, JSON (de-)serialization § Optimizations in the rendering process § Depending on the scenario, Blazor WASM in .NET 5 is 2-3x faster § Performance test suite is available on Github Blazor WebAssembly Neues in .NET 5 Internal improvements for better runtime performance

Slide 14

Slide 14 text

14 § Blazor WASM app bundle size is quite large § .NET assemblies being downloaded into the browser § Downloading adds waiting time for the user § .NET 5 offers server-side prerendering for Blazor WASM § Prerendering significantly speeds up app bootstrap § Page is rendered on server and sent to client as static HTML § Turning on prerendering means testing the entire application for prerendering § Pages are “executed” on the server first § Challenge when client-side security is involved Blazor WebAssembly Neues in .NET 5 Prerendering: Optimizing perceived app loading behavior

Slide 15

Slide 15 text

15 Blazor WebAssembly Neues in .NET 5 Without prerendering https://jonhilton.net/blazor-wasm-prerendering/

Slide 16

Slide 16 text

16 Blazor WebAssembly Neues in .NET 5 With prerendering https://jonhilton.net/blazor-wasm-prerendering/

Slide 17

Slide 17 text

17 § “My app is slow!!!” § “And only because I want to download and display 1000s of rows in my data grid at once!?” § A user can only view so many data rows, anyway § Paging is a well-known technique § Endless scrolling is another one § If you want to optimize rendering performance of list data, then you can use the component in .NET 5 § Only the visible elements are in the DOM § Can be used with data all in memory – or fetch data dynamically Blazor WebAssembly Neues in .NET 5 Virtualization: Optimizing amounts of data rendered

Slide 18

Slide 18 text

18 Blazor WebAssembly Neues in .NET 5 Component Enhancements

Slide 19

Slide 19 text

19 § In Blazor 3.2, CSS had to be global § One big app.css § No intrinsic component-specific styles easily possible § With .NET 5, Blazor components can be completely encapsulated, including styles § “Namespaced” to the component § CSS supported out-of-the box § Styles will be merged at compile time and included in one file via tag § SASS support easy to implement with Nuget packages, e.g. LibSassBuilder Blazor WebAssembly Neues in .NET 5 Isolated CSS & SASS: Component-specific styles

Slide 20

Slide 20 text

20 § Non-trivial Blazor projects still need interop with JavaScript code § Using browser web APIs § Using 3rd party libraries § JavaScript interop supports JS modules in .NET 5 § No more putting JS code onto window § JS modules can be imported via IJSRuntime § No more adding JS file references in index page § Further helps for completely encapsulated components Blazor WebAssembly Neues in .NET 5 Isolated JS: Component-specific interop code

Slide 21

Slide 21 text

21 § When building modules - e.g. with RCLs - we want to be able to load them only when we need them § Upon routing or via call via an API § Blazor WASM in .NET 5 has simple ability to load assemblies/DLLs based on routes § Not really suited for full modularization § An entry point needed to execute startup code is not supported § Need to get rid of DI in your code § Real lazy loading available via open-source project blazor-lazy-loading § Not yet ported to .NET 5 Blazor WebAssembly Neues in .NET 5 Lazy loading: Delay loading of application parts/modules

Slide 22

Slide 22 text

22 Blazor WebAssembly Neues in .NET 5 The Road Ahead

Slide 23

Slide 23 text

23 Blazor WebAssembly Neues in .NET 5 Looking ahead: .NET 6 https://github.com/dotnet/aspnetcore/issues/27883

Slide 24

Slide 24 text

Danke! Bei Fragen kontaktiert mich gerne Christian Weyer https://thinktecture.com/christian-weyer @christianweyer [email protected] Demos: https://github.com/thinktecture/blazor-wasm-things-to-know Artikel zu Blazor, PWA, Web Components, Angular, .NET Core & mehr: https://thinktecture.com/de/newsletter

Slide 25

Slide 25 text

25 § Breaking changes in .NET 5 § https://docs.microsoft.com/en-us/dotnet/core/compatibility/5.0 § Update Blazor WASM project from .NET Core 3.1 to .NET 5 § https://docs.microsoft.com/en-us/aspnet/core/migration/31-to-50?view=aspnetcore- 5.0&tabs=visual-studio#update-blazor-webassembly-projects § Blazor WASM performance test suite § https://github.com/dotnet/aspnetcore/tree/master/src/Components/benchmarkapps/Wasm.Perfor mance/TestApp § LiveSharp § https://www.livesharp.net/blazor/ § https://twitter.com/christianweyer/status/1336636250464395264 § Lazy loading modules § https://github.com/isc30/blazor-lazy-loading § LibSassBuilder § https://github.com/johan-v-r/LibSassBuilder Blazor WebAssembly Neues in .NET 5 Resources