prerender/prerender — pull request #142 by frankiethekneeman (2014-11-28 08:03:57+00:00)
Title: Add download completion notification through window.prerenderDownloadComplete

I work at a media company using a self hosted fleet of prerender servers to keep our site SEOable by google. One major frustration we've been having is that because of a host of resources placed on our page which are important for ad revenue but not important for SEO, the prerender download check always goes all the way to the timeout before moving on to the JS checking. This leads to the server overshooting the `window.prerenderReady` boolean - often by long enough to do some pretty serious SEO damage to the page. We'd appreciate the ability to notify prerender directly that the important resources have been downloaded, so that the server can move past the download waiting earlier.

We think that other sites might benefit from this ability, so I'm opening this MR to add that functionality.

To that effect, I've changed the downloadChecker logic from a `setInterval` to a recursive `setTimeout`, and used the `page.evaluate` functionality from phantomJS to ascertain the existence and value of a `window.prerenderDownloadComplete` variable. By setting this to `true`, a site can notify the prerender server that the important resources have been downloaded and allow it to move on, ensuring that the page renders more predictably through prerender.

While I was editing the `server.checkIfPageIsDoneLoading` function, I took the liberty of cleaning up some of the check logic into more self-documenting variables, but I assure you the base functionality is unchanged, and sites using prerender are will not find themselves more error prone because of this feature.

I tested as much as I could on my local, but I had trouble Identifying any unit tests that could be use to more confidently declare this patch functional and backwards compatible. We are dedicated to this functionality, however, and would like very much to see it included in prerender - it's a great codebase, and we're excited to help make it better. Please let us know what we can do to make this work for you.