ArticleslgStudy

computer science

Blazor

Blazor is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Blazor rather than just read about it. In short: Blazor is a free and open-source web framework that enables developers to create web user interfaces (UI) based on components, using C# and HTML. It is being developed by Microsoft, as part of the ASP.NET Core web app framework.

Blazor — main illustration
Blazor — illustration

Key takeaways

  • Blazor belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Blazor to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Blazor from memory before moving on to harder problems.

Reference excerpt

Blazor is a free and open-source web framework that enables developers to create web user interfaces (UI) based on components, using C# and HTML. It is being developed by Microsoft, as part of the ASP.NET Core web app framework. Blazor can be used to develop single-page, mobile, or server-rendered applications using .NET technologies.

History In 2017, at NDC Oslo, Steve Sanderson, software engineer at Microsoft, unveiled an experimental client-side web application framework for .NET that he called "Blazor". The demo involved an interactive app running in the browser using WebAssembly and a rudimentary development experience in Visual Studio. Sanderson demonstrated how to build interactive components using C# and Razor syntax. The app was then compiled to .NET assemblies that were running on a lightweight third-party open-source .NET runtime, called DotNetAnywhere, that had been compiled to WebAssembly. The name, "Blazor", as explained by Steve Sanderson, is a portmanteau of the words "browser" and "razor" (from the Razor syntax being used). Blazor was admitted as an official open-source project by Microsoft, and in 2018, as part of .NET Core 3.0, Blazor Server was released to the public. It enabled server-driven interactive web apps that update the client browser via WebSockets. Shortly thereafter, Blazor WebAssembly was released. Unlike the prototype, it used the Mono .NET runtime on WebAssembly. This is the same runtime that is used for developing mobile apps with .NET MAUI (previously Xamarin). The Blazor source code was first located in its own repository on GitHub, until it was merged into the ASP.NET Core monorepo. The development has been carried out from there ever since. With the release of .NET 5, Blazor stopped working on Internet Explorer and the legacy version of Microsoft Edge. In 2023, with .NET 8, Blazor on the server underwent some fundamental changes to enable server-side rendered (SSR) pages that are not fundamentally interactive, allowing Blazor to be used as an alternative to MVC Razor Pages. With this change, developers can opt-in per component (or page) whether it should be interactive, and whether it should run on the server or in the browser using WebAssembly. These are referred to as Interactive "Render modes".

Components Components are formally referred to as Razor components. A Razor component consists mainly of HTML that is mixed with Razor templating syntax that enables the inline-use of C# to influence the rendering. The Blazor component model makes sure that the rendered markup gets updated when the state of the component changes, usually in response to user action. While both markup and C# code can be placed in the same .razor file, it is also possible to have a separate code-behind file with a partial class. Components are compiled into .NET classes. The HTML and Razor markup of a component gets translated into code that builds a render tree that then drives the actual rendering.

Example The following example shows how to implement a simple counter that can be incremented by clicking a button:

Hosting models Blazor apps can be hosted in multiple ways. These are the hosting models as of .NET 8.

Blazor Web app (Server) A server-hosted Blazor app, as part of an ASP.NET Core app.

Static server-side rendering (SSR) By default, components are rendered by the server as static HTML, without any interactivity. Interactivity can be enabled per component by setting a render mode. This is equivalent to how MVC views and Razor Pages are rendered.

Render modes Source: In .NET 8, Blazor introduced the concept of render modes which configure whether Razor components are interactive and what drives that interactivity. The render mode is inherited within a component hierarchy, from its top most parent component that has a set render mode. This can not be overridden by child components, unless its render mode is the default Static Server.

Static Server – The component is rendered statically on the server with no interactivity. This is the default. Interactive Server – The component is running on the server in interactive mode. The interactivity is server-driven and changes are pushed to the client over WebSocket, using SignalR. Interactive WebAssembly – The component is running in interactive mode in the browser using WebAssembly. Interactive Auto – This will initially load the component in the Interactive Server render mode while the Blazor bundle is downloaded. On subsequent visits Interactive WebAssembly is used on the client.

Prerendering Interactive components are pre-rendered on the server before being materialized on the client and interactivity kicking in. This behavior is turned on by default, but can be turned off.

Enhanced navigation This feature makes navigation on a static site much smoother in a way that feels like a Single Page application (SPA). When navigating from one static page to another, the app intercepts the navigation, retrieving just the content of the target page, and then apply only the changes to the DOM. That way the page doesn't flicker as it usually does when being completely reloaded upon navigating to another page.

WebAssembly (Standalone) This is a standalone interactive WebAssembly app running in the client browser. Upon navigating to the app in a browser, the app bundle get downloaded, then loaded and executed within the browser's sandbox. A WebAssembly app can also be made into a Progressive web app (PWA). Prior to .NET 8, there was a project template in which a Blazor WebAssembly app was hosted within an ASP.NET Core application containing Web APIs. This was removed in favor of the Blazor Web app project template, although the functionality still remains.

Hybrid Allows Blazor apps to run within a native app using a WebView. Rendering is performed in the hosting process, without a web server. Hybrid apps can be hosted in Windows Presentation Foundation or WinForms application. This approach is used for building native mobile apps with Blazor, using .NET MAUI.

Server (Legacy) The intended use was to enable server-driven interactive components, with changes being sent out to the client using WebSockets. A component was rendered within a MVC Razor Page. It also enabled prerendering of WebAssembly components. This hosting model was formally referred to as "Blazor Server". It has been deprecated in favor of Blazor Web app.

See also

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Blazor

Start with the simplest possible case. Write down what Blazor claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Blazor before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Blazor ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Blazor

In research
Blazor appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Blazor in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Blazor is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2018 software, ASP.NET, Cross-platform software, so understanding it makes those chapters shorter.
In everyday life
Look for Blazor outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Blazor” →

How to study Blazor in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Blazor means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Blazor out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Blazor in simple terms?

Blazor is a free and open-source web framework that enables developers to create web user interfaces (UI) based on components, using C# and HTML. It is being developed by Microsoft, as part of the ASP.NET Core web app framework.

Why does Blazor matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Blazor?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Blazor.

Tags

  • 2018 software
  • ASP.NET
  • Cross-platform software
  • Internet properties established in 2018
  • Microsoft application programming interfaces
  • Microsoft development tools
  • Software using the Apache license
  • Web programming

Keep exploring