$30 off During Our Annual Pro Sale. View Details »

Theme Development with the REST API

Jack Lenox
September 23, 2014

Theme Development with the REST API

A talk about WordPress theme development using the REST API that I gave at WordPress Leeds' September Dev Night.

Jack Lenox

September 23, 2014
Tweet

More Decks by Jack Lenox

Other Decks in Technology

Transcript

  1. REST API • Pure data (JSON) • Fast • Due

    in WordPress core in 4.1/4.2 (probably Spring 2015) • Available now as a plugin: wp-api.org • There is also a public WordPress.com REST API that you can use with any self-hosted site via Jetpack…
  2. Y u build theme with REST API? • Speed •

    More engaging user experience • Better mobile experience • More control (failed connections etc.)
  3. Just some recommendations • {{ mustache }} • Backbone •

    HTML5/JS stuff: localStorage, WebSockets, Application Cache
  4. What is {{ mustache }}? • Logic-less templating language •

    Pure <markup> with the occasional {{ placeholder }} • Can be used by a whole load of languages • Importantly in this instance, PHP and JavaScript
  5. What’s Backbone? • Super-lightweight JavaScript framework • MVC(ish) • Essentially

    designed to improve the organisation of your JavaScript • Designed for interaction with REST APIs (that’s lucky isn’t it?)
  6. Challenges • SEO? • JavaScript (what if it isn’t enabled?)

    • WordPress options… • Customisable permalinks? • Customizerrrrrr? • Plugins omgbbq?
  7. Rise to the challenges! • SEO – non-JS backup •

    JS – non-JS backup • WordPress options – umm, we’ll come back to this later
  8. localStorage • We can put a lot of stuff in

    here to speed things up (post URLs and IDs) • Possibly even REST API responses? • Maybe load stuff asynchronously when user first visits the site?
  9. WebSockets • Use this instead of AJAX for our additional

    requests • Ratchet (PHP library for WebSockets)
  10. Application Cache • We can create a proper offline experience

    for users • Any JS can run when the user isn't connected to the internet if it's stored in Application Cache • There are a lot of complications around Application Cache • Hopefully in the not too distant future we can use Service Worker instead