Server Rendering?
See original GitHub issueThe Problem
Server-side rendering mostly improves the following aspects of web-applications. They’re arguably the most important ones:
- Time to load. The client can already start rendering without even loading the
.js
- Search engine optimization. Most SEs (notable exception: Google) don’t parse JavaScript-only websites or rank them down. Responding with a “real” HTML solves this perfectly.
- Especially reduces initial load times on mobile.
- Greatly improve the experience for people that disabled javascript. Especially given that
hyperapp
’s router uses plain links that work on the server-side too.
Proposed Usage
- Create an
app()
that works on the client-side. - Require said
app()
on the server-side - Render it somehow (maybe with a
hyperapp/server
, so that the client-version isn’t polluted ) - Get a string or buffer back
- Return said buffer via HTTP/etc.
So basically, the same as react. 😄
Notable Challenges
Router
has to be able to run on the server-side. I suggest we add astate.router.url
property to thestate
for both browser and server usage. Ifstate.router.url
is defined, the router should always make sure to set the browser URL to that URL too.
Bonus feature?
Just thought about file-sizes. Wouldn’t it be possible to somehow re-use the already rendered HTML version to make the javascript components even smaller? Maybe gzip already fixes that if you bundle the JS as well. Not sure.
Is this possible or planned? Would be awesome if this could completely replace React.
Issue Analytics
- State:
- Created 7 years ago
- Comments:38 (27 by maintainers)
Top Results From Across the Web
What is Server-Side Rendering? Definition and FAQs
Server -side rendering (SSR) is an application's ability to convert HTML files on the server into a fully rendered HTML page for the...
Read more >Client-side vs. server-side rendering: why it's not all black and ...
Server -side rendering is the most common method for displaying information onto the screen. It works by converting HTML files in the server...
Read more >Rendering on the Web
Server rendering generates the full HTML for a page on the server in response to navigation. This avoids additional round-trips for data ...
Read more >What is server-side rendering? - Educative.io
Server -side rendering (SSR), is the ability of an application to contribute by displaying the web-page on the server instead of rendering it...
Read more >What is server-side rendering: definition, benefits and risks
Server -side rendering (SSR) is a technique that renders a web page on the server rather than in the browser. When a website's...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@benjaminj6 The approach you laid out is nice & clean, but I think we may need to have an instance of
hyperapp
loaded up on the server-side in order to execute the lifecycle hooks and plugins (mixins) that someone may be using. Probably not the fullhyperapp
, but something similar enough which invokes all the hooks then spits out HTML.Here’s a couple ideas with the router. 1st idea, you register it like normal, but it’s a special version designed to handle Node.
Alternatively, the server version of
router
is just thematch
function that turns a URL into the state object. This is probably not ideal for the router, though, since something could trigger a url redirect action during this process, but for simpler plugins it’s an option.And yes, I called them plugins, as a form of protest 😛
Thoughts?
My vote would be to build in streaming support, similar to Vue. It allows a much higher throughput on the server by breaking up the rendering into smaller async chunks. I haven’t dug into how they implemented that, though.
A simple
toString
would be a great first step, though, and from there you can do perf benchmarking to see what could be improved, I suppose.Another interesting strategy is what
marko
does. They write blog posts claiming their SSR performance is the fastest around.https://hackernoon.com/server-side-rendering-shootout-with-marko-preact-rax-react-and-vue-25e1ae17800f