-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clarify book structure + add necessary explanations
- Loading branch information
1 parent
a496b2d
commit 28869f2
Showing
6 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Wrapping Up Part 1: Client-Side Rendering | ||
|
||
So far, everything we’ve written has been rendered almost entirely in the browser. When we create an app using Trunk, it’s served using a local development server. If you build it for production and deploy it, it’s served by whatever server or CDN you’re using. In either case, what’s served is an HTML page with | ||
|
||
1. the URL of your Leptos app, which has been compiled to WebAssembly (WASM) | ||
2. the URL of the JavaScript used to initialized this WASM blob | ||
3. an empty `<body>` element | ||
|
||
When the JS and WASM have loaded, Leptos will render your app into the `<body>`. This means that nothing appears on the screen until JS/WASM have loaded and run. This has some drawbacks: | ||
|
||
1. It increases load time, as your user’s screen is blank until additional resources have been downloaded. | ||
2. It’s bad for SEO, as load times are longer and the HTML you serve has no meaningful content. | ||
3. It’s broken for users for whom JS/WASM don’t load for some reason (e.g., they’re on a train and just went into a tunnel before WASM finished loading; they’re using an older device that doesn’t support WASM; they have JavaScript or WASM turned off for some reason; etc.) | ||
|
||
These downsides apply across the web ecosystem, but especially to WASM apps. | ||
|
||
However, depending the on the requirements of your project, you may be fine with these limitations. | ||
|
||
If you just want to deploy your Client-Side Rendered website, skip ahead to the chapter on ["Deployment"](https://leptos-rs.github.io/leptos/deployment/index.html) - there, you'll find directions on how best to deploy your Leptos CSR site. | ||
|
||
|
||
But what do you do if you want to return more than just an empty `<body>` tag in your `index.html` page? Use “Server-Side Rendering”! | ||
|
||
Whole books could be (and probably have been) written about this topic, but at its core, it’s really simple: rather than returning an empty `<body>` tag, with SSR, you'll return an initial HTML page that reflects the actual starting state of your app or site, so that while JS/WASM are loading, and until they load, the user can access the plain HTML version. | ||
|
||
Part 2 of this book, on Leptos SSR, will cover this topic in some detail! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
# Server Side Rendering | ||
# Part 2: Server Side Rendering | ||
|
||
So far, everything we’ve written has been rendered almost entirely in the browser. When we create an app using Trunk, it’s served using a local development server. If you build it for production and deploy it, it’s served by whatever server or CDN you’re using. In either case, what’s served is an HTML page with | ||
The second part of the book is all about how to turn your beautiful UI's into full-stack, "Universal" Rust + Leptos powered websites and applications. | ||
|
||
1. the URL of your Leptos app, which has been compiled to WebAssembly (WASM) | ||
2. the URL of the JavaScript used to initialized this WASM blob | ||
3. an empty `<body>` element | ||
As you read in the last chapter, there are some limitations to using Client-Side Rendered Leptos apps - over the next few chapters, you'll see how we can overcome those limitations | ||
and get the best performance and SEO out of your Leptos apps. | ||
|
||
When the JS and WASM have loaded, Leptos will render your app into the `<body>`. This means that nothing appears on the screen until JS/WASM have loaded and run. This has some drawbacks: | ||
Let's see how we can use the full power of Leptos and Rust on the server to make your next cutting-edge application! | ||
|
||
1. It increases load time, as your user’s screen is blank until additional resources have been downloaded. | ||
2. It’s bad for SEO, as load times are longer and the HTML you serve has no meaningful content. | ||
3. It’s broken for users for whom JS/WASM don’t load for some reason (e.g., they’re on a train and just went into a tunnel before WASM finished loading; they’re using an older device that doesn’t support WASM; they have JavaScript or WASM turned off for some reason; etc.) | ||
|
||
These downsides apply across the web ecosystem, but especially to WASM apps. | ||
```admonish info | ||
So what do you do if you want to return more than just an empty `<body>` tag? Use “server-side rendering.” | ||
When working with Leptos on the server side, you're free to choose either the Actix-web or the Axum integrations - the full feature set of Leptos is available with either option. | ||
Whole books could be (and probably have been) written about this topic, but at its core, it’s really simple: rather than returning an empty `<body>` tag, return an initial HTML page that reflects the actual starting state of your app or site, so that while JS/WASM are loading, and until they load, the user can access the plain HTML version. | ||
If, however, you need deploy to a WinterCG-compatible runtime like Deno, Cloudflare, etc., then choose the Axum integration as this deployment option is only available with Axum on the server. Lastly, if you'd like to go full-stack WASM/WASI and deploy to WASM-based serverless runtimes, then Axum is your go-to choice here too. | ||
The rest of this section will cover this topic in some detail! | ||
NB: this is a limitation of the web frameworks themselves, not Leptos. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Building User Interfaces | ||
# Part 1: Building User Interfaces | ||
|
||
This first section will introduce you to the basic tools you need to build a reactive | ||
user interface using Leptos. By the end of this section, you should be able to | ||
build a simple, synchronous application that is rendered in the browser. | ||
In the first part of the book, we're going to look at building user interfaces on the client-side using Leptos. Under the hood, Leptos and Trunk are bundling up a snippet of Javascript which will load up the Leptos UI, which has been compiled to WebAssembly to drive the interactivity in your CSR (client-side rendered) website. | ||
|
||
Part 1 will introduce you to the basic tools you need to build a reactive user interface powered by Leptos and Rust. By the end of Part 1, you should be able to | ||
build a snappy synchronous website that's rendered in the browser and which you can deploy on any static-site hosting service, like Github Pages or Vercel. |