SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
1
- Behind the scenes of "Awesome Blazor Browser" -
Pre-render
Blazor WebAssembly
on static web hosting at publishing time
2
2
Introduction
- What's "Awesome Blazor Browser"?
3
3
"Awesome Blazor Browser"
A dedicated web app for browsing the README of the
"Awesome Blazor" GitHub repository.
▪ It's a Blazor WebAssembly app (SPA).
▪ It's hosted on GitHub Pages.
▪ It's deployed by GitHub Actions.
▪ It provides us with easy navigation and
searching for the "Awesome Blazor"
collection.
• It fetches the README text from the
"Awesome Blazor" GitHub repository, parses,
restructures it, and shows the collection in a
searchable UI.
https://j.mp/awesome-blazor-browser 3
4
The "Awesome Blazor Browser" had a problem…
The Internet search result of the "Awesome Blazor Browser" was really bad.
- Currently, Google crawlers can index of a content that Blazor Wasm apps rendered.
- The server-side prerendering strategy is also effective when the app is hosted on an ASP.NET Core server.
See also: https://andrewlock.net/enabling-prerendering-for-blazor-webassembly-apps/
5
5
"Pre-rendering" at publishing time can resolve it.
• It's something like "Static Site Generation (SSG)".
• Make the published "index.html" to contains the same
content that the app renders into the browser after launching
the app.
• Additionally, if the app has some route URL, each URL should
be rendered and be saved into a corresponding static HTML.
• In this case, we have to do this in a GitHub Actions script
that publishes the site.
6
6
How to pre-render a Blazor
WebAssembly app at publishing time?
7
7
Create your own pre-render C# program
• Add an ASP.NET Core server project
for hosting the Blazor WebAssembly.
• And configure it to server-side render
with "static" render mode.
• Add an app that boots the host and
fetches contents from the host by
HttpClient and saves them to static
HTML files.
For more detail, see also "andrewlock.net".
Use the "react-snap"
• "react-snap" is a NodeJS tool.
• It traverses the published SPA contents
using a headless Chromium browser
and saves them to static HTML files.
• The Blazor WebAssembly side is not
required any code changes.
For more detail, see also "swimburger.net".
I could find some solutions on the Internet.
8
8
…But I could not be satisfied with those solutions.
Create your own pre-render C# program
• We have to write massive and
complicated C# codes.
• Those C# codes depend on individual
Blazor WebAssembly project strongly.
• That means the programs of this
approach can't reuse out-of-the-box for
the other Blazor WebAssembly project.
Use the "react-snap"
• It can't wait for an "OnInitializedAsync"
async method to be completed.
• Therefore, in some cases, it saved an
intermediate content result.
• It saves client-side process rendered
HTML, so the results are a bit different
from server-side rendered HTML.
• So, we must rewrite pre-rendered HTML
files after "react-snap" does.
9
9
…So, I started yet another project to
resolve it.
"Reinvent a wheel? Yes, I know."
10
10
My approach
and goal are:
Based on standard server-side
prerendering that is hosted on
an ASP.NET Core server.
Make the code changes of the
Blazor WebAssembly side to be
minimum.
Make it as a NuGet package.
11
11
…and finally, I did it !
"BlazorWasmPreRendering.Build"
https://www.nuget.org/packages/BlazorWasmPreRendering.Build/
12
12
Only you need to do is just adding that package!
> dotnet add package BlazorWasmPreRendering.Build --version 1.0.0-preview.4.1
13
13
An output of "dotnet publish" before adding this package
14
14
An output of "dotnet publish" after adding this package
15
15
Before After
In this case, I used the "Toolbelt.Blazor.HeadElement" NuGet package to change the document title.
See also: https://dev.to/j_sakamoto/yet-another-way-to-changing-the-page-title-in-blazor-and-more-43k
16
You don't need to change the GitHub action script.
In this case, I used the "PublishSPAforGitHubPages.Build"
NuGet package to simplify publishing the Blazor
WebAssembly app to GitHub Pages.
See also: https://dev.to/j_sakamoto/the-easier-way-to-
publish-your-blazor-webassembly-app-for-github-pages-319l
This package also works on the
GitHub Action script to deploy to
Azure Static Web apps.
17
17
What does the
"BlazorWasmPreRendering.Build" do?
18
18
"BlazorWasmPreRendering.Build" does…
• It starts its own ASP.NET Core web server instance.
• The server instance loads the published "index.html" file and
creates the SPA fallback Razor page on the fly from that
"index.html".
• The server instance also loads the Blazor components DLL files
from the publish folder and finds an "App" root component.
• It configures the SPA fallback Razor page to do server-side
rendering with "static" rendering mode.
• It sends HTTP requests to itself and saves the responses to
static HTML files in the publish folder.
19
19
Load
1st. Initializing step
📦 "BlazorWasmPreRendering.Build" 📂 Publish Folder ("/")
📄 "Index.html"
🎛 Web Server
🕹 Crawler
📂 "/_frameworks"
📄 "MyApp.dll"
...
<body>
<div id="app">
Loading...
</div>
...
</body>
📄 "_Host.cshtml"
</div>
...
</body>
...
<body>
<div id="app">
Loading...
@Html.RenderComponentAsync( ,…)
typeof(App) Load
20
20
2nd. Crawling step
📦 "BlazorWasmPreRendering.Build" 📂 Publish Folder ("/")
📄 "Index.html"
🎛 Web Server
🕹 Crawler
HTTP Request GET "/"
Response
<h1>Home</h1>
...
<a href="counter">
Counter</a>
... Save
<h1>Home</h1>
...
<a href="counter">
Counter</a>
...
Render
Detect Link
Response
<h1>Counter</h1>
... Save
<h1>Counter</h1>
...
Render
HTTP Request GET "/counter"
📂 "/counter"
📄 "index.html"
href="counter"
21
21
2nd. Crawling step
📦 "BlazorWasmPreRendering.Build" 📂 Publish Folder ("/")
📄 "Index.html"
🎛 WebHost
🕹 Crawler
HTTP Request GET "/"
Response
<h1>Home</h1>
...
<a href="counter">
Counter</a>
... Save
<h1>Home</h1>
...
<a href="counter">
Counter</a>
...
Render
Detect Link
Response
<h1>Counter</h1>
... Save
<h1>Counter</h1>
...
Render
HTTP Request GET "/counter"
📂 "/counter"
📄 "index.html"
href="counter"
These processes are executed just before the end of "dotnet publish".
22
22
But of course, it is not perfect.
"No Silver Bullet" ― Frederick Phillips Brooks, Jr.
23
23
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
var services = builder.Services;
var baseAddress = builder.HostEnvironment.BaseAddress;
await builder.Build().RunAsync();
}
"BlazorWasmPreRendering.Build" can't invoke the
Main method of the Blazor Wasm app side.
• "BlazorWasmPreRendering.Build"
runs your Blazor app on its own
server process.
• When your app depends on
custom services in a DI container,
but the "Main" method never be
invoked in the server process, the
app will fail because any services
are not registered to the DI
container in the server process.
services.AddTransient(sp => new HttpClient {
BaseAddress = new Uri(baseAddress) });
services.AddSingleton<MyService>();
Never invoked! 😱
24
24
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
var services = builder.Services;
var baseAddress = builder.HostEnvironment.BaseAddress;
await builder.Build().RunAsync();
}
So, you have to extract service registrations to
a method named "ConfigureServices()".
• "BlazorWasmPreRendering.Build"
will invoke this Blazor Wasm app's
"ConfigureServices()" method
within its startup process.
private static void ConfigureServices(
IServiceProvider services, string baseAddress)
{
}
ConfigureServices(services, baseAddress);
services.AddTransient(sp => new HttpClient {
BaseAddress = new Uri(baseAddress) });
services.AddSingleton<MyService>();
Will be invoked! 👍
25
25
And this is still an experimental project.
• There are few results of using the
"BlazorWasmPreRendering.Build" yet.
• I'm not sure currently that "BlazorWasmPreRendering.Build"
works well on complicated real-world applications or not.
• I am still interested in the "react-snap" approach if it can
avoid the problem that it can't wait for the async initialization
because developers may use this approach with an out-of-
the-box experience.
26
26
Conclusion
27
27
I hope "BlazorWasmPreRendering.Build" will save
your time
• This package will improve the Internet
search results of your static hosting
Blazor Wasm app with only minimal or
no code changes.
• But this is still an experimental project.
• I welcome anybody who forks and
improve this project or implement
other approaches.
28
28
Appendix
• "Yet another way to changing the page title in Blazor, and more." | DEV Community
https://dev.to/j_sakamoto/yet-another-way-to-changing-the-page-title-in-blazor-and-more-43k
• "The easier way to publish your Blazor WebAssembly app for GitHub Pages" | DEV Community
https://dev.to/j_sakamoto/the-easier-way-to-publish-your-blazor-webassembly-app-for-github-pages-319l
29
29
THANK YOU!
Lean, Practice, Share.

Contenu connexe

Tendances

Git and GitHub for Documentation
Git and GitHub for DocumentationGit and GitHub for Documentation
Git and GitHub for DocumentationAnne Gentle
 
An Introduction to Software Testing
An Introduction to Software TestingAn Introduction to Software Testing
An Introduction to Software TestingThorsten Frommen
 
Hire Amazon Virtual Assistants from Data4Amazon.com
Hire Amazon Virtual Assistants from Data4Amazon.comHire Amazon Virtual Assistants from Data4Amazon.com
Hire Amazon Virtual Assistants from Data4Amazon.comData4Amazon
 
Create an online bookstore
Create an online bookstoreCreate an online bookstore
Create an online bookstoreJaved Khan
 
Web Development Presentation
Web Development PresentationWeb Development Presentation
Web Development PresentationTurnToTech
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | IntroductionJohnTaieb
 
How to design a poster using Canva
How to design a poster using CanvaHow to design a poster using Canva
How to design a poster using CanvaJudeCosson
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Gitatishgoswami
 
REST APIs and MQ
REST APIs and MQREST APIs and MQ
REST APIs and MQMatt Leming
 
Getting Started with the Alma API
Getting Started with the Alma APIGetting Started with the Alma API
Getting Started with the Alma APIKyle Banerjee
 
Managing the Complexity of Microservices Deployments
Managing the Complexity of Microservices DeploymentsManaging the Complexity of Microservices Deployments
Managing the Complexity of Microservices DeploymentsApigee | Google Cloud
 
Welcome to CMS Distribution
Welcome to CMS DistributionWelcome to CMS Distribution
Welcome to CMS DistributionSean Jinks
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategiesjstack
 
Git Branching for Agile Teams
Git Branching for Agile Teams Git Branching for Agile Teams
Git Branching for Agile Teams Atlassian
 
Front end development session1
Front end development session1Front end development session1
Front end development session1marwa Ayad Mohamed
 
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)Cliff Seal
 

Tendances (20)

Git and GitHub for Documentation
Git and GitHub for DocumentationGit and GitHub for Documentation
Git and GitHub for Documentation
 
Fastapi
FastapiFastapi
Fastapi
 
An Introduction to Software Testing
An Introduction to Software TestingAn Introduction to Software Testing
An Introduction to Software Testing
 
Hire Amazon Virtual Assistants from Data4Amazon.com
Hire Amazon Virtual Assistants from Data4Amazon.comHire Amazon Virtual Assistants from Data4Amazon.com
Hire Amazon Virtual Assistants from Data4Amazon.com
 
Create an online bookstore
Create an online bookstoreCreate an online bookstore
Create an online bookstore
 
Web Development Presentation
Web Development PresentationWeb Development Presentation
Web Development Presentation
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Progressive Web App
Progressive Web AppProgressive Web App
Progressive Web App
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
How to design a poster using Canva
How to design a poster using CanvaHow to design a poster using Canva
How to design a poster using Canva
 
Serving ML easily with FastAPI
Serving ML easily with FastAPIServing ML easily with FastAPI
Serving ML easily with FastAPI
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
REST APIs and MQ
REST APIs and MQREST APIs and MQ
REST APIs and MQ
 
Getting Started with the Alma API
Getting Started with the Alma APIGetting Started with the Alma API
Getting Started with the Alma API
 
Managing the Complexity of Microservices Deployments
Managing the Complexity of Microservices DeploymentsManaging the Complexity of Microservices Deployments
Managing the Complexity of Microservices Deployments
 
Welcome to CMS Distribution
Welcome to CMS DistributionWelcome to CMS Distribution
Welcome to CMS Distribution
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
 
Git Branching for Agile Teams
Git Branching for Agile Teams Git Branching for Agile Teams
Git Branching for Agile Teams
 
Front end development session1
Front end development session1Front end development session1
Front end development session1
 
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
 

Similaire à Pre-render Blazor WebAssembly on static web hosting at publishing time

Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyImran Sayed
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Zach Lendon
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementZach Lendon
 
Pump up the JAM with Gatsby
Pump up the JAM with GatsbyPump up the JAM with Gatsby
Pump up the JAM with GatsbyStefan Adolf
 
Server deployment
Server deploymentServer deployment
Server deploymentbsadd
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsSarvesh Kushwaha
 
Using the WordPress REST API and Gatsby.js
Using the WordPress REST API and Gatsby.jsUsing the WordPress REST API and Gatsby.js
Using the WordPress REST API and Gatsby.jsIndigo Tree Digital
 
Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"
Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"
Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"Fwdays
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...Technical Tips: Visual Regression Testing and Environment Comparison with Bac...
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...Building Blocks
 
Lazy load Website Assets
Lazy load Website AssetsLazy load Website Assets
Lazy load Website AssetsChris Love
 
Migrating from Pivotal tc Server on-prem to IBM Liberty in the cloud
Migrating from Pivotal tc Server on-prem to IBM Liberty in the cloudMigrating from Pivotal tc Server on-prem to IBM Liberty in the cloud
Migrating from Pivotal tc Server on-prem to IBM Liberty in the cloudJohn Donaldson
 
Top React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdfTop React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdfKaty Slemon
 
Top 8 react static site generators for 2020
Top 8 react static site generators for 2020Top 8 react static site generators for 2020
Top 8 react static site generators for 2020Katy Slemon
 

Similaire à Pre-render Blazor WebAssembly on static web hosting at publishing time (20)

Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With Gatsby
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
 
Azure Serverless Conf
Azure Serverless ConfAzure Serverless Conf
Azure Serverless Conf
 
Spring boot
Spring bootSpring boot
Spring boot
 
Pump up the JAM with Gatsby
Pump up the JAM with GatsbyPump up the JAM with Gatsby
Pump up the JAM with Gatsby
 
Blazor.pptx
Blazor.pptxBlazor.pptx
Blazor.pptx
 
Server deployment
Server deploymentServer deployment
Server deployment
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
 
Using the WordPress REST API and Gatsby.js
Using the WordPress REST API and Gatsby.jsUsing the WordPress REST API and Gatsby.js
Using the WordPress REST API and Gatsby.js
 
Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"
Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"
Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"
 
vitepress-en.pdf
vitepress-en.pdfvitepress-en.pdf
vitepress-en.pdf
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...Technical Tips: Visual Regression Testing and Environment Comparison with Bac...
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...
 
Lazy load Website Assets
Lazy load Website AssetsLazy load Website Assets
Lazy load Website Assets
 
Migrating from Pivotal tc Server on-prem to IBM Liberty in the cloud
Migrating from Pivotal tc Server on-prem to IBM Liberty in the cloudMigrating from Pivotal tc Server on-prem to IBM Liberty in the cloud
Migrating from Pivotal tc Server on-prem to IBM Liberty in the cloud
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
Blazor
BlazorBlazor
Blazor
 
Top React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdfTop React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdf
 
Top 8 react static site generators for 2020
Top 8 react static site generators for 2020Top 8 react static site generators for 2020
Top 8 react static site generators for 2020
 

Plus de Jun-ichi Sakamoto

C# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へ
C# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へC# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へ
C# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へJun-ichi Sakamoto
 
WebAssemblyが切り拓くフロントエンドWeb開発の未来
WebAssemblyが切り拓くフロントエンドWeb開発の未来WebAssemblyが切り拓くフロントエンドWeb開発の未来
WebAssemblyが切り拓くフロントエンドWeb開発の未来Jun-ichi Sakamoto
 
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とはがんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とはJun-ichi Sakamoto
 
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LTAzure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LTJun-ichi Sakamoto
 
C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点
C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点
C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点Jun-ichi Sakamoto
 
C# で Single Page Web アプリを 開発できる Blazor ― その魅力
C# で Single Page Web アプリを開発できる Blazor ― その魅力C# で Single Page Web アプリを開発できる Blazor ― その魅力
C# で Single Page Web アプリを 開発できる Blazor ― その魅力Jun-ichi Sakamoto
 
Azure App Service Authentication
Azure App Service AuthenticationAzure App Service Authentication
Azure App Service AuthenticationJun-ichi Sakamoto
 
ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」
ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」
ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」Jun-ichi Sakamoto
 
「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編
「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編
「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編Jun-ichi Sakamoto
 
Ohotech特盛#14 セッション4 予告編
Ohotech特盛#14 セッション4 予告編Ohotech特盛#14 セッション4 予告編
Ohotech特盛#14 セッション4 予告編Jun-ichi Sakamoto
 
CLR/H 第99回勉強会ライトニングトーク
CLR/H 第99回勉強会ライトニングトークCLR/H 第99回勉強会ライトニングトーク
CLR/H 第99回勉強会ライトニングトークJun-ichi Sakamoto
 
Ohotech特盛#13 スマホで操作する カメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―
Ohotech特盛#13 スマホで操作するカメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―Ohotech特盛#13 スマホで操作するカメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―
Ohotech特盛#13 スマホで操作する カメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―Jun-ichi Sakamoto
 
はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!
はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!
はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!Jun-ichi Sakamoto
 
息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみた息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみたJun-ichi Sakamoto
 
More Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトーク
More Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトークMore Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトーク
More Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトークJun-ichi Sakamoto
 
One horror stories around NuGet
One horror stories around NuGetOne horror stories around NuGet
One horror stories around NuGetJun-ichi Sakamoto
 
How to automated test a web application with sending e mail feature
How to automated test a web application with sending e mail featureHow to automated test a web application with sending e mail feature
How to automated test a web application with sending e mail featureJun-ichi Sakamoto
 
Introduction of "MarkdownPresenter"
Introduction of "MarkdownPresenter"Introduction of "MarkdownPresenter"
Introduction of "MarkdownPresenter"Jun-ichi Sakamoto
 
セッション中に Twitter につぶやく!
セッション中に Twitter につぶやく!セッション中に Twitter につぶやく!
セッション中に Twitter につぶやく!Jun-ichi Sakamoto
 
Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!
Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!
Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!Jun-ichi Sakamoto
 

Plus de Jun-ichi Sakamoto (20)

C# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へ
C# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へC# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へ
C# で SPA を作る BLAZOR WEBASSEMBLY の進化 - そしてその先へ
 
WebAssemblyが切り拓くフロントエンドWeb開発の未来
WebAssemblyが切り拓くフロントエンドWeb開発の未来WebAssemblyが切り拓くフロントエンドWeb開発の未来
WebAssemblyが切り拓くフロントエンドWeb開発の未来
 
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とはがんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
 
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LTAzure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
 
C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点
C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点
C# で Single Page Web アプリが開発できるフレームワーク&開発環境 「Blazor」 ― その概要と Web アプリ開発者にもたらす利点
 
C# で Single Page Web アプリを 開発できる Blazor ― その魅力
C# で Single Page Web アプリを開発できる Blazor ― その魅力C# で Single Page Web アプリを開発できる Blazor ― その魅力
C# で Single Page Web アプリを 開発できる Blazor ― その魅力
 
Azure App Service Authentication
Azure App Service AuthenticationAzure App Service Authentication
Azure App Service Authentication
 
ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」
ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」
ライトニングトーク - とある LINE Bot の開発記「とても腹立たしいことがあったのです」
 
「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編
「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編
「ゆるくLTをしよう勉強会@旭川」jsakamoto 予告編
 
Ohotech特盛#14 セッション4 予告編
Ohotech特盛#14 セッション4 予告編Ohotech特盛#14 セッション4 予告編
Ohotech特盛#14 セッション4 予告編
 
CLR/H 第99回勉強会ライトニングトーク
CLR/H 第99回勉強会ライトニングトークCLR/H 第99回勉強会ライトニングトーク
CLR/H 第99回勉強会ライトニングトーク
 
Ohotech特盛#13 スマホで操作する カメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―
Ohotech特盛#13 スマホで操作するカメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―Ohotech特盛#13 スマホで操作するカメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―
Ohotech特盛#13 スマホで操作する カメラ付きWi-Fiラジコンカー ― C#とラズパイとWebアプリの技術で作っちゃおう! ―
 
はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!
はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!
はじめよう TypeScript - 入門から実践まで - 素の JavaScript とはさようなら!
 
息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみた息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための &lt;s>HTML5&lt;/s> Web標準 アプリ作ってみた
 
More Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトーク
More Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトークMore Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトーク
More Azure Websites! - JAZUGさっぽろ "きたあず" 第5回勉強会ライトニングトーク
 
One horror stories around NuGet
One horror stories around NuGetOne horror stories around NuGet
One horror stories around NuGet
 
How to automated test a web application with sending e mail feature
How to automated test a web application with sending e mail featureHow to automated test a web application with sending e mail feature
How to automated test a web application with sending e mail feature
 
Introduction of "MarkdownPresenter"
Introduction of "MarkdownPresenter"Introduction of "MarkdownPresenter"
Introduction of "MarkdownPresenter"
 
セッション中に Twitter につぶやく!
セッション中に Twitter につぶやく!セッション中に Twitter につぶやく!
セッション中に Twitter につぶやく!
 
Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!
Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!
Ohotech特盛#5予告 - タートルグラフィックでいろんな模様を描いてみよう!
 

Dernier

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Pre-render Blazor WebAssembly on static web hosting at publishing time

  • 1. 1 - Behind the scenes of "Awesome Blazor Browser" - Pre-render Blazor WebAssembly on static web hosting at publishing time
  • 3. 3 3 "Awesome Blazor Browser" A dedicated web app for browsing the README of the "Awesome Blazor" GitHub repository. ▪ It's a Blazor WebAssembly app (SPA). ▪ It's hosted on GitHub Pages. ▪ It's deployed by GitHub Actions. ▪ It provides us with easy navigation and searching for the "Awesome Blazor" collection. • It fetches the README text from the "Awesome Blazor" GitHub repository, parses, restructures it, and shows the collection in a searchable UI. https://j.mp/awesome-blazor-browser 3
  • 4. 4 The "Awesome Blazor Browser" had a problem… The Internet search result of the "Awesome Blazor Browser" was really bad. - Currently, Google crawlers can index of a content that Blazor Wasm apps rendered. - The server-side prerendering strategy is also effective when the app is hosted on an ASP.NET Core server. See also: https://andrewlock.net/enabling-prerendering-for-blazor-webassembly-apps/
  • 5. 5 5 "Pre-rendering" at publishing time can resolve it. • It's something like "Static Site Generation (SSG)". • Make the published "index.html" to contains the same content that the app renders into the browser after launching the app. • Additionally, if the app has some route URL, each URL should be rendered and be saved into a corresponding static HTML. • In this case, we have to do this in a GitHub Actions script that publishes the site.
  • 6. 6 6 How to pre-render a Blazor WebAssembly app at publishing time?
  • 7. 7 7 Create your own pre-render C# program • Add an ASP.NET Core server project for hosting the Blazor WebAssembly. • And configure it to server-side render with "static" render mode. • Add an app that boots the host and fetches contents from the host by HttpClient and saves them to static HTML files. For more detail, see also "andrewlock.net". Use the "react-snap" • "react-snap" is a NodeJS tool. • It traverses the published SPA contents using a headless Chromium browser and saves them to static HTML files. • The Blazor WebAssembly side is not required any code changes. For more detail, see also "swimburger.net". I could find some solutions on the Internet.
  • 8. 8 8 …But I could not be satisfied with those solutions. Create your own pre-render C# program • We have to write massive and complicated C# codes. • Those C# codes depend on individual Blazor WebAssembly project strongly. • That means the programs of this approach can't reuse out-of-the-box for the other Blazor WebAssembly project. Use the "react-snap" • It can't wait for an "OnInitializedAsync" async method to be completed. • Therefore, in some cases, it saved an intermediate content result. • It saves client-side process rendered HTML, so the results are a bit different from server-side rendered HTML. • So, we must rewrite pre-rendered HTML files after "react-snap" does.
  • 9. 9 9 …So, I started yet another project to resolve it. "Reinvent a wheel? Yes, I know."
  • 10. 10 10 My approach and goal are: Based on standard server-side prerendering that is hosted on an ASP.NET Core server. Make the code changes of the Blazor WebAssembly side to be minimum. Make it as a NuGet package.
  • 11. 11 11 …and finally, I did it ! "BlazorWasmPreRendering.Build" https://www.nuget.org/packages/BlazorWasmPreRendering.Build/
  • 12. 12 12 Only you need to do is just adding that package! > dotnet add package BlazorWasmPreRendering.Build --version 1.0.0-preview.4.1
  • 13. 13 13 An output of "dotnet publish" before adding this package
  • 14. 14 14 An output of "dotnet publish" after adding this package
  • 15. 15 15 Before After In this case, I used the "Toolbelt.Blazor.HeadElement" NuGet package to change the document title. See also: https://dev.to/j_sakamoto/yet-another-way-to-changing-the-page-title-in-blazor-and-more-43k
  • 16. 16 You don't need to change the GitHub action script. In this case, I used the "PublishSPAforGitHubPages.Build" NuGet package to simplify publishing the Blazor WebAssembly app to GitHub Pages. See also: https://dev.to/j_sakamoto/the-easier-way-to- publish-your-blazor-webassembly-app-for-github-pages-319l This package also works on the GitHub Action script to deploy to Azure Static Web apps.
  • 18. 18 18 "BlazorWasmPreRendering.Build" does… • It starts its own ASP.NET Core web server instance. • The server instance loads the published "index.html" file and creates the SPA fallback Razor page on the fly from that "index.html". • The server instance also loads the Blazor components DLL files from the publish folder and finds an "App" root component. • It configures the SPA fallback Razor page to do server-side rendering with "static" rendering mode. • It sends HTTP requests to itself and saves the responses to static HTML files in the publish folder.
  • 19. 19 19 Load 1st. Initializing step 📦 "BlazorWasmPreRendering.Build" 📂 Publish Folder ("/") 📄 "Index.html" 🎛 Web Server 🕹 Crawler 📂 "/_frameworks" 📄 "MyApp.dll" ... <body> <div id="app"> Loading... </div> ... </body> 📄 "_Host.cshtml" </div> ... </body> ... <body> <div id="app"> Loading... @Html.RenderComponentAsync( ,…) typeof(App) Load
  • 20. 20 20 2nd. Crawling step 📦 "BlazorWasmPreRendering.Build" 📂 Publish Folder ("/") 📄 "Index.html" 🎛 Web Server 🕹 Crawler HTTP Request GET "/" Response <h1>Home</h1> ... <a href="counter"> Counter</a> ... Save <h1>Home</h1> ... <a href="counter"> Counter</a> ... Render Detect Link Response <h1>Counter</h1> ... Save <h1>Counter</h1> ... Render HTTP Request GET "/counter" 📂 "/counter" 📄 "index.html" href="counter"
  • 21. 21 21 2nd. Crawling step 📦 "BlazorWasmPreRendering.Build" 📂 Publish Folder ("/") 📄 "Index.html" 🎛 WebHost 🕹 Crawler HTTP Request GET "/" Response <h1>Home</h1> ... <a href="counter"> Counter</a> ... Save <h1>Home</h1> ... <a href="counter"> Counter</a> ... Render Detect Link Response <h1>Counter</h1> ... Save <h1>Counter</h1> ... Render HTTP Request GET "/counter" 📂 "/counter" 📄 "index.html" href="counter" These processes are executed just before the end of "dotnet publish".
  • 22. 22 22 But of course, it is not perfect. "No Silver Bullet" ― Frederick Phillips Brooks, Jr.
  • 23. 23 23 public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add<App>("#app"); var services = builder.Services; var baseAddress = builder.HostEnvironment.BaseAddress; await builder.Build().RunAsync(); } "BlazorWasmPreRendering.Build" can't invoke the Main method of the Blazor Wasm app side. • "BlazorWasmPreRendering.Build" runs your Blazor app on its own server process. • When your app depends on custom services in a DI container, but the "Main" method never be invoked in the server process, the app will fail because any services are not registered to the DI container in the server process. services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(baseAddress) }); services.AddSingleton<MyService>(); Never invoked! 😱
  • 24. 24 24 public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add<App>("#app"); var services = builder.Services; var baseAddress = builder.HostEnvironment.BaseAddress; await builder.Build().RunAsync(); } So, you have to extract service registrations to a method named "ConfigureServices()". • "BlazorWasmPreRendering.Build" will invoke this Blazor Wasm app's "ConfigureServices()" method within its startup process. private static void ConfigureServices( IServiceProvider services, string baseAddress) { } ConfigureServices(services, baseAddress); services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(baseAddress) }); services.AddSingleton<MyService>(); Will be invoked! 👍
  • 25. 25 25 And this is still an experimental project. • There are few results of using the "BlazorWasmPreRendering.Build" yet. • I'm not sure currently that "BlazorWasmPreRendering.Build" works well on complicated real-world applications or not. • I am still interested in the "react-snap" approach if it can avoid the problem that it can't wait for the async initialization because developers may use this approach with an out-of- the-box experience.
  • 27. 27 27 I hope "BlazorWasmPreRendering.Build" will save your time • This package will improve the Internet search results of your static hosting Blazor Wasm app with only minimal or no code changes. • But this is still an experimental project. • I welcome anybody who forks and improve this project or implement other approaches.
  • 28. 28 28 Appendix • "Yet another way to changing the page title in Blazor, and more." | DEV Community https://dev.to/j_sakamoto/yet-another-way-to-changing-the-page-title-in-blazor-and-more-43k • "The easier way to publish your Blazor WebAssembly app for GitHub Pages" | DEV Community https://dev.to/j_sakamoto/the-easier-way-to-publish-your-blazor-webassembly-app-for-github-pages-319l