csharpfritz / csharp_with_csharpfritz

Show notes, slides, and samples from the CSharp with CSharpFritz show
MIT License
659 stars 215 forks source link

GitHub Actions to Compile Blazor WebAssembly for SEO at Static Website Hosing #111

Closed nakigoe closed 2 years ago

nakigoe commented 2 years ago

Hi Jeffery, thank you for your lessons and your answers!

How to get my Blazor WebAssembly website indexed for SEO?

I had Blazor WebAssembly Hosted Prerendered running locally (it's great, it can even run on Internet Explorer 11!!!) This was a default Blazor WebAssembly Hosted with modified settings according to Microsoft Docs for prerendering: https://docs.microsoft.com/aspnet/core/blazor/components/prerendering-and-integration

FetchData.razor throws an error: «There is no registered service of type 'System.Net.Http.HttpClient'»,

What can be wrong?

I really hate server-side hosting, they either offer services that I never use if I pay ahead, or charge with hidden fees once they get one's bank card when charging 'per usage'.

For example, the problem with AWS is, that having 0-5 visitors a day, with Blazor WebAssembly I received the following message: Your AWS account has exceeded 85% of the usage limit for one or more AWS Free Tier-eligible services for the month of March. (5Gb)

$0.023 per GB build artifacts stored 42.458 GigaBytes $0.98 Vat included $1.20 in March What????? Where do these 45 GigaBytes come from?

So I'm staying with static Blazor WebAssembly for now, they have 100Gb/month free bandwidth on Vercel.com

csharpfritz commented 2 years ago

WebAssembly pages are not currently indexed by the search engines like Google and Bing. The way around it is to prerender with a server using ASP.NET Core.

45GB of activity is a LOT of content in build artifacts. How are you building your application? I don't see anywhere near this volume with GitHub actions and Azure Static Websites

nakigoe commented 2 years ago

That was the stupid code from a very popular Internet post on AWS Blazor WebAssembly hosting:

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - curl -sSL https://dot.net/v1/dotnet-install.sh > dotnet-install.sh
        - chmod +x *.sh
        - ./dotnet-install.sh -c 6.0.3 -InstallDir ./dotnet6
        - ./dotnet6/dotnet --version
    build:
      commands:
        - ./dotnet6/dotnet publish -c Release -o release
  artifacts:
    baseDirectory: /release/wwwroot
    files:
      - '**/*'
  cache:
    paths: []

AWS Amplify provides a Docker container, everything was fine until the bill came. Probably the correct solution would be:

  1. to compile the website with GitHub actions to the repo branch, like «gh-pages» (I have this one covered for Blazor WebAssembly)
  2. connect the branch with compiled code to a hosting provider. (works perfectly for Blazor WebAssembly)
csharpfritz commented 2 years ago

No.. a static webassembly site will not compile into content that can be search-indexed in the current state of search engine crawlers.

You will need to render the web assembly content with something like server-side rendering like ASP.NET Core hosting.

Andrew Lock wrote an article describing an approach to render pages without ASP.NET Core: https://andrewlock.net/prerending-a-blazor-webassembly-app-without-an-asp-net-core-host-app/