0.7.2 • Published 8 years ago
connect-prerenderer v0.7.2
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.
- "default" --- check "/PRERENDER-" prefix which will be removed, and replace "HASH-" to "#/" and all "-"s to "/"s to make a target URL. (see the source code for more options.)
- "googlebot" --- follow https://developers.google.com/webmasters/ajax-crawling/docs/getting-started
- a function that returns a target URL for prerendering or null.
- 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
towindow.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 theRENDERER_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 (useclass
).
AngularJS only limitations:
ng-repeat
workaround only works withng-repeat
attributes.ng-repeat-(start|end)
is not supported.
0.7.2
8 years ago
0.7.1
8 years ago
0.7.0
8 years ago
0.6.4
10 years ago
0.6.3
10 years ago
0.6.2
10 years ago
0.6.1
10 years ago
0.6.0
10 years ago
0.5.8
11 years ago
0.5.7
11 years ago
0.5.6
11 years ago
0.5.5
11 years ago
0.5.4
11 years ago
0.5.3
11 years ago
0.5.2
11 years ago
0.5.1
11 years ago
0.5.0
11 years ago
0.4.3
11 years ago
0.4.2
11 years ago
0.4.1
11 years ago
0.4.0
11 years ago
0.3.8
11 years ago
0.3.7
11 years ago
0.3.6
11 years ago
0.3.5
11 years ago
0.3.4
11 years ago
0.3.2
11 years ago
0.3.1
11 years ago
0.3.0
11 years ago
0.2.3
11 years ago
0.2.2
11 years ago
0.2.1
11 years ago
0.2.0
11 years ago
0.1.1
11 years ago
0.1.0
11 years ago