Giter VIP home page Giter VIP logo

above-the-fold-only-server-render's Introduction

above-the-fold-only-server-render

NPM version Build Status Dependency Status

A React component for optionally skipping server side rendering of components outside above-the-fold (or outside of the viewport). This component helps render your components on the server that are above the fold and the remaining components on the client.

Performance

AboveTheFoldOnlyServerRender helps increase performance both by decreasing the load on renderToString and sending the end user a smaller amount of markup.

The following table outlines a clear performance increase in the example app by skipping server rendering on the Walmart.com Footer component and several other below the fold zones:

HTML Size renderToString Time
before 452 kB 249 ms
after 315 kB 177 ms
diff -137 kB (-30%) -72 ms (-29%)

Installation

npm install above-the-fold-only-server-render

Usage

By default, the AboveTheFoldOnlyServerRender component simply returns the child component. You can tell the component to skip server rendering either by passing a prop skip={true} or setting up aboveTheFoldOnlyServerRender in your app context and passing the component a contextKey prop.

You can skip server side rendering by passing a skip prop:

import { AboveTheFoldOnlyServerRender } from "above-the-fold-only-server-render";

const SomeComponent = () => {
  return (
    <AboveTheFoldOnlyServerRender skip={true}>
      <div>This will not be server side rendered.</div>
    </AboveTheFoldOnlyServerRender>
  );
};

You can also skip server side rendering by setting context and passing a contextKey prop:

import { AboveTheFoldOnlyServerRender } from "above-the-fold-only-server-render";

const SomeComponent = () => {
    return (
      <AboveTheFoldOnlyServerRender contextKey="aboveTheFoldOnlyServerRender.SomeComponent">
        <div>This will not be server side rendered based on the context.</div>
      </AboveTheFoldOnlyServerRender>
    );
};

class SomeApp extends React.Component {
  getChildContext() {
    return {
      aboveTheFoldOnlyServerRender: {
        SomeComponent: true
      }
    };
  }

  render() {
    return (
      <SomeComponent />
    );
  }
}

SomeApp.childContextTypes = {
  aboveTheFoldOnlyServerRender: React.PropTypes.shape({
    AnotherComponent: React.PropTypes.bool
  })
};

Development Guide

We have an ever-green guide to our development practices with this archetype. Click here before starting development on a component library.

Scripts

To run the demo:

gulp demo

To view the demo, navigate to http://localhost:4000

To view the demo with hot reload enabled, navigate to http://localhost:4000/webpack-dev-server/

To run tests:

gulp test

To build /lib:

gulp build

npm link

When using npm link, you must delete react from zeus-components-layout/node_modules/. This is because npm link is just a symlink, not a proper npm install.

You must also run gulp build

Built with ❤️ by Team Electrode @WalmartLabs.

above-the-fold-only-server-render's People

Contributors

ananavati avatar caoyangs avatar jchip avatar jeffrifwald avatar tiffine-koch avatar

Watchers

 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.