Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderToString vs renderToStream #26

Closed
jiangfengming opened this issue Nov 29, 2016 · 10 comments
Closed

renderToString vs renderToStream #26

jiangfengming opened this issue Nov 29, 2016 · 10 comments
Assignees

Comments

@jiangfengming
Copy link

jiangfengming commented Nov 29, 2016

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’s 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)
@atinux
Copy link
Member

atinux commented Nov 29, 2016

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!

@atinux atinux added this to the 1.0 milestone Nov 29, 2016
@jiangfengming
Copy link
Author

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!

@atinux atinux self-assigned this Dec 12, 2016
@atinux
Copy link
Member

atinux commented Dec 12, 2016

It will be implemented before the 1.0.0 👍

@f15gdsy
Copy link

f15gdsy commented Apr 5, 2017

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

@slrohit
Copy link

slrohit commented Apr 30, 2017

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

@f15gdsy
Copy link

f15gdsy commented Apr 30, 2017

@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.

@dohomi
Copy link

dohomi commented May 1, 2017

@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.

@pi0
Copy link
Member

pi0 commented May 14, 2017

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.

@atinux atinux closed this as completed Jun 20, 2017
@atinux atinux removed this from 0.11.0 in Roadmap 1.0 Jun 20, 2017
@piglovesyou
Copy link

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

@lock
Copy link

lock bot commented Nov 5, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 5, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants