An adventure in headless CMS' and modern web development
+
"Modern" web apps and SPAs became a thing circa IPhone 4, when we decided Flash was a bad idea.
This guys' to blame :D
WordPress is used by 42.8% of the web* (October 2021)
Still, when it comes to web applications*, it's rarely a serious contender.
But businesses change, requirements change, and sometimes, we're "stuck" with it.
And that "stuck" part was exactly the inspiration for this talk.
Problem statement
Re-use existing WP data and user base
Re-use plugin logic as much as reasonable
WooCommerce has to work
It has to provide an app-like experience
...and I don't know WordPress π¬
Happily enough, WP has an API
WooCommerce has one too
They do GraphQL too (via plugins)*
Strategy and approach
Use the core WP API for content and users
Use the WooCommerce API for all things shopping
?
profit
Enter Astro.js
A static-site generator that also does SSR
Aims for zero JS
Component based
"Islands" architecture
Works really well with headless CMS
// Title.astro
<div>
<h1>I'm an Astro component</h1>
</div>
---
import Title from './Title.astro';
---
<main>
<Title />
</main>
---
import Title from './Title.astro';
---
<main>
<Title />
</main>
---
// Title.astro
const title = "I'm an Astro component";
---
<div>
<h1>{title}</h1>
</div>
---
import Title from './Title.astro';
---
<main>
<Title />
</main>
---
// Title.astro
const props = Astro.props;
---
<div>
<h1>{props.title}</h1>
</div>
---
import Title from './Title.astro';
---
<main>
<Title title="I'm an Astro component" />
</main>
---
// Example: Use a static React component on the page, without JavaScript.
import MyReactComponent from '../components/MyReactComponent.jsx';
---
<!-- 100% HTML, Zero JavaScript loaded on the page! -->
<MyReactComponent />
<!-- This component is now interactive on the page!
The rest of your website remains static and zero JS. -->
<MyReactComponent client:load />
More about directives at: https://docs.astro.build/en/reference/directives-reference/#client-directives
You now know about 70% of what Astro is about.
Strategy and approach (updated)
Use the core WP API for content and users
Use the WooCommerce API for all things shopping
Use Astro for everything front-end
Remember - an island can be an app unto itself
profit
+
Setup
WP via docker
Fakerpress for some data
WPGraphql for a GraphQL API
A WooCommerce client library
Astro, with an existing theme
+
Lessons learned, benefits and drawbacks
Questions?
βοΈ https://darko.io