Lazy Hydration of Server-Side Rendered Vue.js Components
npm install vue-lazy-hydration



> Lazy Hydration of Server-Side Rendered Vue.js Components

vue-lazy-hydration is a renderless Vue.js component to improve Estimated Input Latency and Time to Interactive of server-side rendered Vue.js applications. This can be achieved by using lazy hydration to delay the hydration of pre-rendered HTML.
``bash`
npm install vue-lazy-hydration
`js
import LazyHydrate from 'vue-lazy-hydration';
// ...
export default {
// ...
components: {
LazyHydrate,
// ...
},
// ...
};
`
In the example below you can see the four hydration modes in action.
` html
`
1. Because it is at the very top of the page, the ImageSlider should be hydrated eventually, but we can wait until the browser is idle.ArticleContent
2. The component is never hydrated on the client, which also means it will never be interactive (static content only).AdSlider
3. Next we can see the beneath the article content, this component will most likely not be visible initially so we can delay hydration until the point it becomes visible.CommentForm
4. At the very bottom of the page we want to render a but because most people only read the article and don't leave a comment, we can save resources by only hydrating the component whenever it actually receives focus.
Sometimes you might want to prevent a component from loading initially but you want to activate it on demand if a certain action is triggered. You can do this by manually triggering the component to hydrate like you can see in the following example.
`html
`
Because of how this package works, it is not possible to nest multiple root nodes inside of a single Internally the Intersection Observer API is used to determine if a component is visible or not. You can provide Intersection Observer options to the For a list of possible options please take a look at the Intersection Observer API documentation on MDN. Additionally to the This plugin will not work as advertised if you're not using it in combination with SSR. Although it should work with every pre-rendering approach (like Prerender SPA Plugin, Gridsome, ...) I've only tested it with Nuxt.js so far. Breaking changes: - - Specyfing - Partial Hydration Concepts: Lazy and Active The code of the v1 version of this package was based on a similar package created by Rahul Kadyan. Because the core functionality of Execute the following commands to run the integration tests: Execute the following commands to run the performance benchmark: Markus Oberlehner MIT. But you can wrap multiple components with a .`html`
when-visible$3
property to configure the Intersection Observer.`html`
Import Wrappers
wrapper component you can also use Import Wrappers to lazy load and hydrate certain components.`html`
ssr-onlyBenchmarks
$3
$3
Caveats
Upgrade v1.x to v2.x
was renamed to never (as in "Hydrate this? Never!").`diff`
-
+
ignored-props on Import Wrappers is not necessary anymore.`diff`
components: {
- ArticleContent: hydrateNever(() => import('./ArticleContent.vue'), { ignoredProps: ['content'] }),
+ ArticleContent: hydrateNever(() => import('./ArticleContent.vue')),
}vue-lazy-hydrationArticles
- abomination: a Concept for a Static HTML / Dynamic JavaScript Hybrid Application
- How to Drastically Reduce Estimated Input Latency and Time to Interactive of SSR Vue.js ApplicationsCredits
Testing
heavily relies on browser APIs like IntersectionObserver and requestIdleCallback(), it is tough to write meaningful unit tests without having to write numerous mocks. Because of that, we mostly use integration tests and some performance benchmarks to test the functionality of this package.`$3
bash`
npm run test:integration:build
npm run test:integration`$3
bash``
npm run test:perf:build
npm run test:perfAbout
$3
Website: https://markus.oberlehner.net
Twitter: https://twitter.com/MaOberlehner
PayPal.me: https://paypal.me/maoberlehner
Patreon: https://www.patreon.com/maoberlehner$3