I have a Vue.js App working with Server Side Rendering (SSR) and then client side hydration and it works great. I love building isomorphic javascript and think it is the way of the future.
But there is still one issue i would like to solve. Here is a simple diagram:
First we check if we have the cached HTML response
If we do not have cache then we:
This flow i have down and works great. I would like to figure out is how to do the step in blue.
If we have cache I would like to:
I have done some research and I could not find any information about Server Side Hydration. I even looked into other isopmorphic framworks like react and angular 2 to see if they had a solution and could not find one.
I don't mind building something like this but i need a push in the right direction, so if there is someone out there that is working on this kind of thing or has any suggestions, much appreciated.
Vite SSR. Vite provides built-in support for Vue server-side rendering, but it is intentionally low-level.
Hydration refers to the client-side process during which Vue takes over the static HTML sent by the server. and turns it into dynamic DOM that can react to client-side data changes.
Server-side rendering (SSR) is an application's ability to convert HTML files on the server into a fully rendered HTML page for the client. The web browser submits a request for information from the server, which instantly responds by sending a fully rendered page to the client.
1 Answer. Show activity on this post. Vue is primarily client side framework - rendering is done by JS running in the client's browser. Your app has (usually) only one index.
A viable solution is to figure out which components in your app you can cache, and then employ something like Component-level caching ( https://ssr.vuejs.org/guide/caching.html#component-level-caching ) to cache the non-user-specific components, while rendering the user-specific components on each run.
As the document said, the Client Side Hydration is:
In server-rendered output, the root element will have the server-rendered="true" attribute. On the client, when you mount a Vue instance to an element with this attribute, it will attempt to "hydrate" the existing DOM instead of creating new DOM nodes.
For example, the server rendered result is:
<div class="app" id="app" server-rendered="true">
<div class="labrador">Hello Labrador</labrador>
<div class="husky"></div>
</div>
and the client code is:
Vue.component('husky', {
template: '<div class="husky">Hello husky</div>'
})
var rootComp = {
template: '' +
'<div class="app" id="app">' +
' <div class="labrador"></div>' +
' <husky></husky>' +
'</div>'
}
new Vue({
el: '#app',
render: h => h(rootComp)
})
So the client will find the generated virtual DOM tree matches with the DOM structure from the server. After the "Hydration", the final render result will be:
<div class="app" id="app" server-rendered="true">
<div class="labrador">Hello Labrador</labrador>
<div class="husky">Hello husky</div>
</div>
As you see, this is what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With