GithubHelp home page GithubHelp logo

react-server-rendering's Introduction

React server rendering demo

THIS IS NOT OFFICIALLY SUPPORTED.

We aren't prepared to support this in any way other than casually. But React does have a test case to ensure that the core works outside of the browser and we're committed to keeping it working. So if you want to build better server rendering bindings for React on top of this, be my guest!

Warning!

We've tried to do a pretty good job of keeping React modules with minimal internal state, but if you were to roll this out in production you would need to make sure that you clear your module cache between requests, otherwise you could have a privacy bug where info leaks between requests because some state may be lingering inside of your modules. contextify may be good for this.

What is this?

This is a demo of running React on the server to generate the HTML and send it down. JavaScript only attaches the event listeners and leaves the markup intact.

We don't use any sort of fake DOM (jsdom, phantom etc) -- we've just designed React from the ground up to not depend on the browser. So it's fast and memory efficient.

We use the React tutorial application almost completely unmodified.

Why do I want this?

Googlebot, and initial page load times, and overall flexibility in how you can build your app.

How to use:

First:

npm install

To render on the command line:

make commandline

And to run the demo server:

make serve

Go to http://localhost:3000/client-rendered to see plain old client rendered. Then go to http://localhost:3000/server-rendered to see it server rendered.

Try turning off JS and revisiting those URLs.

Also you can try running multiple tabs to see the live updating in the demo.

Why can't I see the comments with JavaScript disabled?

Because we're fetching them via AJAX. You could just as easily preload your comments by designing a fetching API that works on the client and the server, and set up the initial state of your component on the server such that the commments are there on initial load. But I wanted to take an unmodified example that was not designed for server rendering and add server rendering to it.

react-server-rendering's People

Contributors

petehunt avatar vjeux avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.