Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to make a decentralized WordPress website

How to make a decentralized WordPress website

PoP (https://getpop.org) is a WordPress framework which aims to break the information monopoly of large Internet corporations by linking autonomous WordPress websites together, allowing them to interact with each other and become part of a wider network composed of different communities. Users from different websites can interact among themselves, without the need to join a centralized service such as Facebook or LinkedIn. This way, website owners can keep control of their own data, storing it on their own servers.

PoP works by combining WordPress and Handlebars into an MVC architecture framework, in which WordPress is the model, Handlebars is the view, and PoP is the controller. Acting as the controller, PoP intercepts WordPress’ data query results, generates a response in JSON, and feeds this JSON code to Handlebars to be transformed into HTML. The result is a dynamic website, in which the back-end is fully WordPress, yet the front-end is built using javascript.

In this presentation, we will explore the technical features of the framework, how it works, how to create a website with it and how to integrate it within an ecosystem.

Avatar for Leonardo Losoviz

Leonardo Losoviz

June 15, 2017
Tweet

More Decks by Leonardo Losoviz

Other Decks in Programming

Transcript

  1. What is PoP? PoP creates Single-Page Application websites, by combining

    WordPress and Handlebars into an MVC architecture framework: WordPress is the model/back-end Handlebars templates are the view/front-end the PoP engine is the controller
  2. How does it work? 1 PoP intercepts the user request

    in the front-end and delivers it to the webserver using AJAX Front-end Back-end Request Request: AJAX
  3. How does it work? 2 the PoP controller processes the

    request and delivers it to WordPress to get the data Front-end Back-end Request Request: AJAX Data
  4. How does it work? 3 PoP generates a response in

    JSON, and feeds this JSON code back to the front-end Front-end Back-end Request Request: AJAX Response: JSON Data
  5. How does it work? 4 PoP delivers the JSON code

    to Handlebars, which then generates the HTML code using javascript templates, and passes it back to PoP Front-end Back-end Request HTML Request: AJAX Response: JSON Data
  6. How does it work? 5 PoP appends the HTML into

    the DOM and executes user-defined javascript functions on the new elements Front-end Back-end Request: AJAX Response: JSON Data Request HTML Response
  7. #1: API PoP provides the WordPress website of its own

    API: Available via HTTP Simply by adding to any URL: output=json
  8. #2: Decentralized The response is a uniform JSON code All

    PoP websites can communicate among themselves Fetch/process data in real time. POST requests User-generated content is stored on the source website.
  9. Niche/decentralized social network => Twitter/Facebook/ Medium/Reddit (with WooCommerce) Decentralized market-place

    => Amazon Content aggregator => Digg Server back-end for mobile apps Microservices Some potential uses
  10. Single-Page Application User experience similar to that of a desktop

    application Can configure: what pages are preloaded what pages are retrieved from the server
  11. Server-side rendering The first page loaded produces HTML from the

    server The 2nd page onwards, the SPA takes over HTML code produced in the front-end through javascript Isomorphic rendering Same code for producing HTML in front and back-end
  12. Content CDN Dynamic (or mutable) content is made static (or

    immutable) by serving it through a Content Delivery Network (CDN) The best of both worlds: Content is still dynamically generated through WordPress But it can be cached as coming from a static site generator
  13. Offline first Offline first capabilities through the implementation of Service

    Workers the website functions offline performance increases by reducing network requests pages load immediately (from the second access onwards) It is a Progressive Web App
  14. Application state Read operations: state kept in front-end Create/Update/Delete operations:

    handled in the server no dual state, no state synchronization needed
  15. (Non)logged-in user state Rich experience for both logged-in and non

    logged-in users Coherent among stateful/less pages Synchronized among tabs
  16. Program execution flow Model and Controller (application logic, program execution

    flow) in back-end Different to javascript frameworks (eg: AngularJS)
  17. Targets Any page can be opened on any pageSection Simply

    specify attribute “target” in the link, pointing to the pageSection
  18. Tabs Many pages can be opened simultaneously Pages remain accessible

    until closed Users are asked to re-open tabs from previous session
  19. Background (pre)loading Pre-loaded pages, user state, client-server synchronization Initial views

    User logged-in status Page-related user state User notifications Non-cacheable data (eg: posts' comment count)
  20. Interceptors Switches tab to an already-opened page Renders a view

    instantly Allows deep-linking of javascript functions, using an actual, reachable URL
  21. Differences Not RESTful (at least not currently, but it can

    be done) Links keep the same URL as in WordPress Documentation-less API The public API is automatically generated Developers can focus on making the website Immediately loaded (no extra request needed to fetch data)
  22. Template hierarchy Top-down hierarchy: 1 topLevel contains N pageSections 1

    pageSection contains N blocks/blockGroups 1 blockGroup contains N blocks/blockGroups 1 block contains N modules 1 module contains N modules (ad infinitum)
  23. Template: block Is an independent component Keeps its own state

    Can be added to different pageSections, and customized for each
  24. Atomic/reusable module A module is composed of: PHP files .tmpl

    Handlebars templates .js files .css files
  25. Clean JSON structure Database => unique per topLevel Dataset =>

    unique per block State variables => unique per block Configuration => unique per pageSection, block and module
  26. “1. Leverage!” DRY (Don’t Repeat Yourself) WordPress: functionalities provided by

    the community Isomorphic rendering: frontend/backend/email HTML from same code Modules: everything is re-usable Decentralized architecture: microservices
  27. “3. Cache!” Several layers of caching: Server cache (WP Super

    Cache) Configuration cache Content CDN / Asset CDN Service Workers