简体   繁体   中英

React.js server side rendering with Java [without Node.js]

We have an application in pure JSP/JQuery which we are trying to move to ReactJs for maintainability. One of the benefits of ReactJs I am seeing is server side rendering. However, all the examples I have seen of server side rendering utilize Node.js as a server side. We are currently using Tomcat and not so much inclined to deploy node.js just for server side rendering.

I have considered few alternatives such as using Nashorn ( http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/ )

However, Nashorn doesn't seem to be production ready.

Has anyone deployed React.js with server side rendering on Tomcat on production?

Trying to render a Javascript app serverside without NodeJS is an excellent way to torture yourself. Trying to run javascript inside a jvm is even worse. I would recommend against it.

It is possible to render the complete client server side using PhantomJS (which technically runs without Node) or even using xvfb and Chrome on *nix. All have been done, with various degrees of painful debugging.

Running the javascript inside tomcat itself is rather unusual… I can't see the point other than "because we can". My best guess is that nobody is doing that in production.

Why not take a step further with server-side rendering and make real-time single-page web applications in reactive style without Node.js in plain Java language?

The Reactive Server Pages project uses the approach similar to the Elixir Phoenix Live View or Scala Korolev frameworks.

Motivation:

  • Responsive web UI in familiar Java, no client-server APIs, no JS frameworks and npm dependencies management needed;
  • Lightweight SSR generated almost plain HTML page to be SEO friendly;
  • UI components are regular Java classes;
  • Brings application rendering workload and UI logic from a client's browser to the server, your code always stays on your server;
  • Debug UI code as any normal Java code;
  • Built with Java web standards, currently runs on Jetty, but in theory, should work on Tomcat as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM