Function leptos::create_blocking_resource
source · pub fn create_blocking_resource<S, T, Fu>(
source: impl Fn() -> S + 'static,
fetcher: impl Fn(S) -> Fu + 'static
) -> Resource<S, T>
Expand description
Creates a “blocking” Resource
. When server-side rendering is used,
this resource will cause any <Suspense/>
you read it under to block the initial
chunk of HTML from being sent to the client. This means that if you set things like
HTTP headers or <head>
metadata in that <Suspense/>
, that header material will
be included in the server’s original response.
This causes a slow time to first byte (TTFB) but is very useful for loading data that
is essential to the first load. For example, a blog post page that needs to include
the title of the blog post in the page’s initial HTML <title>
tag for SEO reasons
might use a blocking resource to load blog post metadata, which will prevent the page from
returning until that data has loaded.
Note: This is not “blocking” in the sense that it blocks the current thread. Rather, it is blocking in the sense that it blocks the server from sending a response.
When used with the leptos_router and SsrMode::PartiallyBlocked
, a
blocking resource will ensure <Suspense/>
blocks depending on the resource
are fully rendered on the server side, without requiring JavaScript or
WebAssembly on the client.