Nuxt.js: renderToString vs renderToStream

Created on 29 Nov 2016  路  10Comments  路  Source: nuxt/nuxt.js

According to the vue.js docs says:

Vue also supports rendering to a stream, which is preferred for web servers that support streaming. This allows HTML to be written to the response as it鈥檚 generated, rather than all at once at the end. The result is requests are served faster, with no downsides!

I see Nuxt is using renderToString to yield the html string. I'm interested the reason why Nuxt not using renderToStream?

This feature request is available on Nuxt.js community (#c21)
enhancement

Most helpful comment

It will be implemented before the 1.0.0 馃憤

All 10 comments

It was actually to make the code more easy to read and to start with (mostly for the renderRoute function).

Now that Nuxt.js will be soon released in V1, I don't see any inconvenient to use the streams to send back the HTML to the server!

I think providing a stream handler callback will be very useful.

Consider the following scenario:

nuxt-hook

Although Vue.js has a component based cache mechanism, it has several problems:

  • Still need to enter the render process.
  • Too complicated. One URL corresponding to one cached html file is more straightforward.

So I want to implement a vue independent cache system. If Nuxt could provide a hook to let me handle the stream, It will be very nice!

It will be implemented before the 1.0.0 馃憤

Awesome! This mechanism is very helpful for websites with many user-generated-pages!

How to build rest apis in nuxt js,
let say i have a form, i wanted to store from data to database using a rest api, how do i achive this

@slrohit This is out of the job scope of NUXT. NUXT should be just about server-side rendering.

API should be implemented in a separate server, or a middleware if you are using NUXT as a middleware.

@slrohit I recently used https://github.com/zeit/micro for building a rest api, maybe have a look at that repo. Your usecase has nothing to do with NUXT as @f15gdsy mentioned above.

Good to mention that according to vue ssr docs streaming is not recommended as we need to evaluate all async components in order to prepare complete headers. So it may introduce performance downsides! (This is actually not opposite to @fenivana's approach since it is streaming the cached response not during response generation :)) )

Since a lot of the context information (like head information or inlined critical CSS) needs to be appear before the application markup, we essentially have to wait until the stream to complete before we can start making use of these context data.

It is therefore NOT recommended to use streaming mode if you rely on context data populated by component lifecycle hooks.

v1.0 seems to be released soon. Where should I see to know actually Nuxt.js makes use of streaming SSR?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  路  3Comments

jaredreich picture jaredreich  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

uptownhr picture uptownhr  路  3Comments

bimohxh picture bimohxh  路  3Comments