Quotes on Design API v2.0

Published by Chris Coyier

I know at least a couple of you ended up using the original Quotes on Design API. It was kind of an experiment, but it did the trick in that it was an easy way to quickly add random design-related quotes to any site, with full CSS control.

It's major weakness was that on every single page load on every single site using it, it had to hit the database. It was a tiny and quick query, but still, not a very efficient thing to do.

I have now updated it to v2.0, which works about the same way, but is far snappier.

Changes

  • Change to ID name on wrapping div (to a more specific "qod-quotes")
  • Faster loading
  • Only changes quotes every 2 minutes

What I Did

Instead of having the JavaScript (actually PHP in disguise) hit the database every time, it simply loads the quote content from a text file. This text file's contents is overwritten by a script that reads a random quote from the database every 2 minutes (a CRON job on the server fires it off). This, I believe, is known as "ghetto caching".

Future

As I learn more about this stuff, I'd like to ultimately have some options for what it returns. JSON or XML is a strong possibility. Some pre-formatted options are also a possibility.

Using It

This is all there is to it:

<div id="qod-quote">
    ... loading ...
</div>
<script type="text/javascript" src="//quotesondesign.com/api/api-2.0.js"></script>