connect-prerenderer

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

  • 所有者: dai-shi/connect-prerenderer
  • 平台:
  • 许可证:
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

connect-prerenderer

Build Status
npm version

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 waits to prerender.
  • cookieDomain: a domain name to allow passing cookies.
  • attachConsole: when truthy, attach global.console to window.console when prerendering files
    (useful for debugging)
  • subprocess: if truthy, do the rendering in a subprocess (it helps to prevent possible memory leaks in jsdom). You can also set the RENDERER_USE_SUBPROCESS environment variable to any value (except an empty string) to achieve the same result. Try it if you experience memory leaks.

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.

主要指标

概览
名称与所有者dai-shi/connect-prerenderer
主编程语言JavaScript
编程语言JavaScript (语言数: 3)
平台
许可证
所有者活动
创建于2013-03-09 05:08:31
推送于2018-08-18 00:50:16
最后一次提交2018-08-18 09:50:04
发布数0
用户参与
星数161
关注者数7
派生数5
提交数116
已启用问题?
问题数10
打开的问题数0
拉请求数11
打开的拉请求数0
关闭的拉请求数3
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?