Home

Awesome

react-nashorn-example

Blog post: http://augustl.com/blog/2014/jdk8_react_rendering_on_server/

This is a single page web app, where the initial page is also served as plain HTML, without any extra work or code duplication required!

When you click links in the web site (and JS is enabled), the single page web app will do all the page loading with JS. But because the initial page (and all pages) is loaded from the backend, your app will be indexable by Google, and also really fast! You don't have to wait for the JS to load to see the content, since it's served statically from the backend.

Running

You need JDK1.8, see next section if you don't have it.

Run the app with:

lein server

Then open http://localhost:4567 in a browser, and enjoy!

Leiningen is Clojure's build tool, if you don't have it, see https://github.com/technomancy/leiningen

Installing JDK1.8

Linux

Use your package manager!

Alternatively, if you don't want to replace your system java, do the following:

Mac OS X

Please contribute a pull request :)

Windows

Please contribute a pull request :)

Tradeoffs

Your React code has to use plain JS only, and not invoke any 3rd party components that requires a DOM. Facebook React supports rendering to a string without a DOM, which is what we actually do on the back-end. If a component invokes a jQuery plugin, you'll get an exception and the backend won't be able to render that page.

I'm not an experienced React user, so I'm not sure how this problem is typically solved. Pull requests are welcome.

TODO

This is a POC. It would be nice with some kind of reusable library. That can probably happen when this todo-list becomes empty.

Copyright

Copyright © 2014 August Lilleaas