0👍
AFAIK, there is no way to have it rendered only on the server because it’s the main purpose of Nuxt (being isomorphic: server + client).
There is probably some other way to make it a bit more performance efficient.
- [Vuejs]-Is it possible to set multiple classes with ternary expressions?
- [Vuejs]-Laravel API routes not working in production but work in dev environment
0👍
I’ve figured it out.
I’ve created new Header component:
export default {
render(createElement: CreateElement) {
if (process.server) {
const fs = process.server ? require('fs') : null;
const file = fs.readFileSync('./header.txt', 'utf8');
return createElement('div', { domProps: { innerHTML: f } });
}
return createElement('div', { domProps: { innerHTML: this.$el.innerHTML } });
},
}
And I use it instead v-html in main component:
<Header />
<div class="container">
<Nuxt />
</div>
In this way on the server side Nuxt loads file to variable, set html using innerHTML and returns the page to client (without header content stored in component data).
On the client side Header component render what is already inside it.
- [Vuejs]-How to add mixpanel to my SSR quasar project
- [Vuejs]-Match color prop to browser colors/hex/rgb aswell as color vars
0👍
So I know I’m late to the party, but if anyone reads this now, Nuxt3 actually has a solution for this:
https://nuxt.com/docs/guide/directory-structure/components#server-components
These components will only be rendered on the server and will reduce impact on hydration.