Weather WASM

The other Weather page generates data server-side, loads it to the HTML, and then streams the body of the updated HTML to the browser. This version of the page makes a call to the server's hosted API to read data and display it using the WASM client. However, thanks to the new InteractiveAuto (Hybrid) setups in .NET 8, we can take it a step further. On first page load, the server will be able to provider server-side rendering of the page, persist the data that was loaded into a cache-like memory store on the browser, and then when the WASM client is fully downloaded and takes over, pass that data into the client so it doesn't have to ask the server for it again.

If you open the browser's Dev Tools and check Disable Cache, then reload the page, you will notice that the first time the page loads, there is no call to /api/Weather/WeatherForecast. Clicking a different page in the nav and coming back, you will then see the call. This is because the WASM has already taken over and no longer has the cache-like store to pull from and needs to get it again. To further persist caching, your API could use something like Redis to cache the previously loaded response, check to see if there's a valid cache instance present in Redis, and serve its contents as the response instead of taking the longer action of running all the way to the database again.

Loading...

An unhandled error has occurred. Reload