Lazy hydration of server-side rendered Vue.js components




> 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 1. Properties passed to a wrapped component are rendered as an HTML attribute on the root element. 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. - abomination: a Concept for a Static HTML / Dynamic JavaScript Hybrid Application The code of the current implementation of this package is based on a similar package created by Rahul Kadyan. Thanks to his code I'm finally able to build a clean solution for what I dreamed of when I created the abomination. 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`
$3
E.g. would render to Lorem ipsum dolor ... as long as you don't provide content as an ignored property the way you can see in the example above.hydrateWhenVisible
2. When using and hydrateOnInteraction all instances of a certain component are immediately hydrated as soon as one of the instances becomes visible or is interacted with.vue-lazy-hydrationBenchmarks
$3
$3
Caveats
Articles
- 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