npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

connect-prerenderer

v0.7.2

Published

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

Downloads

22

Readme

connect-prerenderer

Build Status

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.