To those familiar with the Wordnik developer site, it looks unchanged. There’s a section for code libraries to connect to our API, examples of applications using the API, and of course the Swagger Sandbox. Functional, simple, and easy to navigate.
But just the other day, the site was totally rewritten in HTML, CSS, and Scala. And the lines of code dropped to 1/10th what they were before. What’s the deal? And what makes it so much snappier now?
As an added benefit, the consumer (your ultimate judge) gets a snappier, lighter weight experience which can even work offline. Sounds great, right? So how is this done?
Note here, the response from the API server is HTML, not JSON. Why is that? Well, we’re keeping the client-side rendering as light-weight as possible. The server is extremely good at efficient generation of XML. The client, however, has to keep state of the DOM during manipulation (there are tricks to lessen this burden, of course), plus this header almost never changes.
So why bother put in the rendering logic on the client? All that’s required is a simple call to `load` the content into the DOM:
The server is just as simple to write. Using Scalatra, we simply generate XML and send it over an HTTP get call.
Now for a simple site like developer.wordnik.com, do you need to do fancy techniques like this? Of course not, but we’re developers, and what better place to show what we consider to be best practices than our developer site, right?