Giter VIP home page Giter VIP logo

connect-prerenderer's Introduction

connect-prerenderer

Express/connect middleware to pre-render ajax page for non-ajax browsers, especially using angular.js

How to use

% npm install connect-prerenderer

In app.js:

var express = require('express');
var prerenderer = require('connect-prerenderer');
var app = express();
app.use(prerenderer());
...

Options

  • targetGenerator: a name or a function to generate a new one for HTTP request.
  • timeout: an integer in milliseconds to specify how long it watis to prerender.
  • cookieDomain: a domain name to allow passing cookies.

Coding conventions (client-side)

  • If an html is prerendered, the body is like: <body data-prerendered="true">
  • When JavaScript code finishes prerendering, it should call: document.onprerendered()

Notes for AngularJS

The following snippet would help AngularJS to work:

<script>
  angular.element(document).ready(function() {
    if (document.body.getAttribute('data-prerendered')) {
      document.addEventListener('click', function() {
        document.removeEventListener('click', arguments.callee, true);
        angular.bootstrap(document.documentElement, []);
        return true;
      }, true);
    } else {
      angular.bootstrap(document.documentElement, []);
    }
  });
</script>

To keep templates for interpolation in a prerendered html, use the modified version of angular.js (v1.2.5) located in test/server/public/.

Limitations

  • style attributes are not preserved by jsdom (use class).

AngularJS only limitations:

  • ng-repeat workaround only works with ng-repeat attributes.
  • ng-repeat-(start|end) is not supported.

connect-prerenderer's People

Contributors

dai-shi avatar meric avatar

Watchers

Rakesh 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.