intertwingly

It’s just data

Automatic Preview


Jacques Distler: It seems rather odd to have both a live preview and a forced-preview.

My required preview is a part of my spam prevention strategy, and is intertwined with my issuances of nonces and captchas; neither of which are typically seen by humans.

So... why not take it to the next step?  If JavaScript is enabled, and the browser is suitably standards compliant, why not automatically prefetch the nonce, captcha, and any warnings that may apply; and insert them (as well as a Submit button) into the page?

All I need is to have a data structure that contains all this information, in a format that is easy to parse.  It turns out that I already do: the preview page itself.  As it is XHTML, it is XML, and therefore amenable to XPath.  And in many cases the information is already in the right form, it merely needs to be imported.  In fact, it turned out to be ridiculously easy to implement.  I trigger based on the first character typed into the textarea.

I’ve tested it on Mozilla and Opera.  If you want to try it, you might need to refresh once to pick up the latest scripts.

Next up (with no particular schedule): live preview right on the comment page; and periodically polling of the comment page and the importation of any new comments that may have been posted while you are composing your comment, though this may only work properly on browsers that understand ETags when used in combination with XMLHttpRequest.  Mark Nottingham has a series of tests that you can point your browser at.

Update: initial implementation of live preview and polling for new comments has now been deployed.