SlideShare a Scribd company logo
WP-API + React with
server rendering
+ =
Developer and teacher
Co-founder of DecodeMTL
Where to find me;
github.com/ziad-saab
@ZiadDotHTML
decodemtl.com
Hello!
I am Ziad Saab
WARNING
This presentation is
full of cats and
code.
#WordCatMTL
lides and source code
Slides
French: ziad.cc/wcmtl-2016-fr.html
English: ziad.cc/wcmtl-2016-en.html
Source c ode
github.com/ziad-saab/decodemtl-wp-frontend
github.com/nyanofthemoon/decodemtl-wp-theme
github.com/nyanofthemoon/recursive-acf-to-wp-rest-api
github.com/nyanofthemoon/decodemtl-api
eam
Paule Lepage
Backend + Proxy API
Lucas Lemonnier
Design + SASS
Ziad Saab
Frontend
tructure of the talk
1.WordPress and the REST API
2.Overview of WP-API + React stack
3.Lessons learned:
a.Metadata and technical SEO
b.Async data loading
c.How to manage i18n?
4.Conclusions
iny timeline
▷ Founded DecodeMTL in 2014
▷ Static website — HTML, CSS, JS
▷ Jekyll generates the site’s pages
▷ Yay! No backend!
▷ Mid-2015: need new site
▷ More dynamic and content-based
▷ Content ⇒ CMS ⇒ WordPress
▷ Dynamic ⇒ AJAX/SPA ⇒ React
Inconvenients
▷ The theme is attached to backend
▷ Monolithic structure
▷ “The Loop”
▷ Have to use PHP for frontend
ordPress...
Advantages
▷ Free and open-source CMS
▷ Community and plugins
▷ Familiar/popular admin tool
▷ Custom post types
▷ Custom fields with ACF
▷ Languages management with
Polylang or WPML
ow to keep only the advantages?
{
"author": 1,
"comment_status": "open",
"content": {
"rendered": "<p>Hello World!</p>n"
},
"date": "2016-06-29T13:53:49",
"date_gmt": "2016-06-29T13:53:49",
"excerpt": {
"rendered": "<p>Hello World!</p>n"
},
"featured_media": 0,
"format": "standard",
"id": 29,
"link": "http://decodemtl.com/...",
"modified": "2016-06-29T13:53:49",
"ping_status": "open",
"slug": "hello-world",
"slug_en": "hello-world",
"slug_fr": "bonjour-monde",
"tags": [],
"title": {
"rendered": "First Post"
},
"type": "post"
}
{
"author": 1,
"comment_status": "open",
"content": {
"rendered": "<p>Hello World!</p>n"
},
"date": "2016-06-29T13:53:49",
"date_gmt": "2016-06-29T13:53:49",
"excerpt": {
"rendered": "<p>Hello World!</p>n"
},
"featured_media": 0,
"format": "standard",
"id": 29,
"link": "http://decodemtl.com/...",
"modified": "2016-06-29T13:53:49",
"ping_status": "open",
"slug": "hello-world",
"slug_en": "hello-world",
"slug_fr": "bonjour-monde",
"tags": [],
"title": {
"rendered": "First Post"
},
"type": "post"
}
I SHOULD BUY
A WP-API...
ow to keep only the advantages?
rchitecture WP-API + React
Backend/
Data
Template
API Proxy
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SUPERBlog!</title>
</head>
<body>
<div id="app">
<!-- i can haz content? -->
</div>
<script src="app.js"></script>
</body>
</html>
erver rendering: sans
erver rendering 101
GET /fr/cours/html-css HTTP/1.1
User-Agent: firefox
Accept-Language: fr, en;q=0.7
...
ExpressJS server with /* route
URL passed to react-router
which returns tree of components
Tree of components passed to
redux-connect which uses
Promise to wait for all data to be
loaded
Page data is loaded to a global store
with the help of redux.
react-dom/server renders the
tree of components and react-
redux injects store data as props
HTTP/1.1 200 OK
Date: Wed, 20 Jan 2038 16:19:42 GMT
Content-Type: text/html
Content-Length: …
<!doctype html>
<html>
<head>
<title><!--react-helmet title--></title>
<!--meta tags I CAN HAZ SEOS??-->
</head>
<body>
<div id=”app”><!-- react-dom --></div>
<script src=”app.js”></script>
<script><!--window.REDUX_STATE--></script>
</body>
</html>
Partagé
850+
Server
100
Client
50
Ines of code
I LIKE MATH...
IT MAKES PEOPLE CRY.
etadata and technical SEO
react-helmet
manages the <head>
<Helmet
defaultTitle="DecodeMTL"
titleTemplate="%s | DecodeMTL"
meta={[
{charset: 'utf-8'},
{property: 'og:site_name', content: '...'},
...
]}
/>
<Helmet title={this.props.post.title} />
etadata and technical SEO - front
const head = Helmet.rewind();
const title = head.title.toString();
// <title>Web Dev | DecodeMTL</title>
const meta = head.meta.toString();
// <meta charset="utf-8"><meta ...> ...
etadata and technical SEO - back
polylang
manages posts and CPT
translation in WordPress
react-intl
manages string translation
in the templates
nternationalization
nternationalization - WordPress
function decodemtl_polylang_slugs($post) {
$language = $polylang->model->get_post_language($post->ID);
$current = $language->slug;
$currentSlug = $post->post_name;
$oppositeSlug = '';
$opposite = ('en' === $current) ? 'fr' : 'en';
$oppositePostId = pll_get_post($post->ID, $opposite);
if ($oppositePostId) {
$oppositePost = get_post($oppositePostId);
$oppositeSlug = $oppositePost->post_name;
}
return array(
'slug_' . $current => $currentSlug,
'slug_' . $opposite => $oppositeSlug
);
}
nternationalization - <head>
<link rel="alternate" hreflang="fr" href="https://...">
PARLEZ-VOUS FRANÇAIS?
nternationalization - routes React
<Route path="/" component={App}>
<Route path="fr" onEnter={() => dispatch(switchLang('fr'))}>
<IndexRoute component={Home}/>
<Route path="blogue" component={Blog} />
<Route path="blogue/:slug" component={BlogPost} />
<Route path="cours" component={Courses} />
<Route path="cours/:slug" component={CoursePage} />
<Route path=":slug" component={SinglePage} />
</Route>
<Route onEnter={() =>dispatch(switchLang('en'))}>
<IndexRoute component={Home}/>
<Route path="blog" component={Blog} />
<Route path="blog/:slug" component={BlogPost} />
<Route path="courses" component={Courses} />
<Route path="courses/:slug" component={CoursePage} />
<Route path=":slug" component={SinglePage} />
</Route>
</Route>
nternationalization - components
<FormattedMessage
id="loadingBox.text"
defaultMessage="Loading..."
/>
<FormattedDate
value={this.props.post.createdAt}
year="numeric"
month="long"
/>
nternationalisation - translation
module.exports = {
"homePage.title": "Bienvenue à DecodeMTL",
"homePage.courses": "Nos cours",
"coursePage.instructor": "Votre instructeur",
"coursePage.schedule": "Horaire du cours",
"coursePage.sessions": "Prochaines sessions",
"loadingBox.text": "Chargement...",
"notFoundPage.title": "404 Non Trouvé!",
...
};
TTP and AJAX
isomorphic-fetch
manages AJAX in front
and HTTP requests in back
TTP and AJAX
fetch('/wp-json/wp/v2/posts')
.then(
function(res) {
return res.json();
}
)
.then(...)
TTP and AJAX
redux-connect
manages the data fetching
synchronization
TTP and AJAX - front
@asyncConnect([
{
deferred: true,
promise: function(opt) {
var slug = opt.params.slug;
return opt.store.dispatch(loadCourse(slug));
}
}
])
class BlogPost extends React.Component {
render() {...}
}
TTP and AJAX - back
app.get('/*', (req, res) => {
const memHistory = createHistory(req.url);
const store = makeStore(memHistory);
const routes = require('./routes');
const options = {history: memHistory, routes: routes, location: req.url};
match(options, function(err, redirectLocation, renderProps) {
if (redirectLocation) {
res.redirect(redirectLocation.pathname + redirectLocation.search);
} else if (renderProps) {
loadOnServer({...renderProps, store})
.then(function() {
const html = ReactDOM.renderToString(
<Provider store={store} key="provider">
<ReduxAsyncConnect {...renderProps} />
</Provider>
);
const head = Helmet.rewind();
const title = head.title.toString();
const meta = head.meta.toString();
const link = head.link.toString();
const finalState = store.getState();
res.render('index', {html, title, meta, link, finalState});
});
}
});
});
emo?
onclusions
▷ Using React for a WordPress theme gives you the
advantages of SPA but also its inconvenients
▷ Server rendering negates some inconvenients like the
lack of content and slow loading times
▷ Server rendering doesn’t require more work if we add
more pages/features — scalable
▷ This method is a bit overkill for a simple blog. A small
ExpressJS app would suffice if you want to stay in JS.
#wordCatMTL
@ZiadDotHTML
@DecodeMTL
hank you

More Related Content

What's hot

EWD 3 Training Course Part 11: Handling Errors in QEWD
EWD 3 Training Course Part 11: Handling Errors in QEWDEWD 3 Training Course Part 11: Handling Errors in QEWD
EWD 3 Training Course Part 11: Handling Errors in QEWD
Rob Tweed
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
Rob Tweed
 
A Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on RailsA Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on Rails
Rafael García
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
Rob Tweed
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
Rob Tweed
 
EWD 3 Training Course Part 16: QEWD Services
EWD 3 Training Course Part 16: QEWD ServicesEWD 3 Training Course Part 16: QEWD Services
EWD 3 Training Course Part 16: QEWD Services
Rob Tweed
 
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
Rob Tweed
 
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
Rob Tweed
 
DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoMagento Dev
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with Composer
Manuele Menozzi
 
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
Rob Tweed
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
Peter Lubbers
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
Vivian S. Zhang
 
Mojolicious
MojoliciousMojolicious
Mojolicious
Marcus Ramberg
 
EWD 3 Training Course Part 19: The cache.node APIs
EWD 3 Training Course Part 19: The cache.node APIsEWD 3 Training Course Part 19: The cache.node APIs
EWD 3 Training Course Part 19: The cache.node APIs
Rob Tweed
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
Edureka!
 
Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)
Kazuaki Matsuo
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Ryan Weaver
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Max Andersen
 

What's hot (20)

EWD 3 Training Course Part 11: Handling Errors in QEWD
EWD 3 Training Course Part 11: Handling Errors in QEWDEWD 3 Training Course Part 11: Handling Errors in QEWD
EWD 3 Training Course Part 11: Handling Errors in QEWD
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
 
A Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on RailsA Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on Rails
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
 
EWD 3 Training Course Part 16: QEWD Services
EWD 3 Training Course Part 16: QEWD ServicesEWD 3 Training Course Part 16: QEWD Services
EWD 3 Training Course Part 16: QEWD Services
 
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
 
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
 
DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus Magento
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with Composer
 
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Ugo Cei Presentation
Ugo Cei PresentationUgo Cei Presentation
Ugo Cei Presentation
 
EWD 3 Training Course Part 19: The cache.node APIs
EWD 3 Training Course Part 19: The cache.node APIsEWD 3 Training Course Part 19: The cache.node APIs
EWD 3 Training Course Part 19: The cache.node APIs
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
 

Viewers also liked

SES Personalization, User Data & Search
SES Personalization, User Data & SearchSES Personalization, User Data & Search
SES Personalization, User Data & SearchJonathan Mendez
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Roy Sivan
 
Building mobile apps with Wordpress REST API
Building mobile apps with Wordpress REST APIBuilding mobile apps with Wordpress REST API
Building mobile apps with Wordpress REST API
Salvador Aguilar [ L.I.O.N ]
 
WordPress: React Way
WordPress: React WayWordPress: React Way
WordPress: React Way
Oleksandr Strikha
 
WP Rest API
WP Rest API WP Rest API
WP Rest API
Vladislav Musílek
 
WordPress, React, oh my! (DevelCZ 2016)
WordPress, React, oh my! (DevelCZ 2016)WordPress, React, oh my! (DevelCZ 2016)
WordPress, React, oh my! (DevelCZ 2016)
Borek Bernard
 
Introduction to WordPress REST API
Introduction to WordPress REST APIIntroduction to WordPress REST API
Introduction to WordPress REST API
Simone D'Amico
 

Viewers also liked (7)

SES Personalization, User Data & Search
SES Personalization, User Data & SearchSES Personalization, User Data & Search
SES Personalization, User Data & Search
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmia
 
Building mobile apps with Wordpress REST API
Building mobile apps with Wordpress REST APIBuilding mobile apps with Wordpress REST API
Building mobile apps with Wordpress REST API
 
WordPress: React Way
WordPress: React WayWordPress: React Way
WordPress: React Way
 
WP Rest API
WP Rest API WP Rest API
WP Rest API
 
WordPress, React, oh my! (DevelCZ 2016)
WordPress, React, oh my! (DevelCZ 2016)WordPress, React, oh my! (DevelCZ 2016)
WordPress, React, oh my! (DevelCZ 2016)
 
Introduction to WordPress REST API
Introduction to WordPress REST APIIntroduction to WordPress REST API
Introduction to WordPress REST API
 

Similar to WordCamp Montreal 2016 WP-API + React with server rendering

Web-Performance
Web-PerformanceWeb-Performance
Web-Performance
Walter Ebert
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs
 
Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020
Matt Raible
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
Dalibor Gogic
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with vue.js
Violetta Villani
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with vue.js
Commit University
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
Matt Raible
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
Kevin DeRudder
 
WordPress and Client Side Web Applications WCTO
WordPress and Client Side Web Applications WCTOWordPress and Client Side Web Applications WCTO
WordPress and Client Side Web Applications WCTO
Roy Sivan
 
HTML 5 - Overview
HTML 5 - OverviewHTML 5 - Overview
HTML 5 - Overview
Marcelio Leal
 
Wordcamp Toronto Presentation
Wordcamp Toronto PresentationWordcamp Toronto Presentation
Wordcamp Toronto Presentation
Roy Sivan
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
Atlassian
 
Coding for entrepreneurs
Coding for entrepreneursCoding for entrepreneurs
Coding for entrepreneurs
Amine Sadry
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017
Matt Raible
 
Bringing the JAMstack to the Enterprise
Bringing the JAMstack to the EnterpriseBringing the JAMstack to the Enterprise
Bringing the JAMstack to the Enterprise
Jamund Ferguson
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Fwdays
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019
Anam Ahmed
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
Antonio Peric-Mazar
 
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2
A.K.M. Ahsrafuzzaman
 

Similar to WordCamp Montreal 2016 WP-API + React with server rendering (20)

Web-Performance
Web-PerformanceWeb-Performance
Web-Performance
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with vue.js
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with vue.js
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
WordPress and Client Side Web Applications WCTO
WordPress and Client Side Web Applications WCTOWordPress and Client Side Web Applications WCTO
WordPress and Client Side Web Applications WCTO
 
HTML 5 - Overview
HTML 5 - OverviewHTML 5 - Overview
HTML 5 - Overview
 
Wordcamp Toronto Presentation
Wordcamp Toronto PresentationWordcamp Toronto Presentation
Wordcamp Toronto Presentation
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
 
Coding for entrepreneurs
Coding for entrepreneursCoding for entrepreneurs
Coding for entrepreneurs
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017
 
Bringing the JAMstack to the Enterprise
Bringing the JAMstack to the EnterpriseBringing the JAMstack to the Enterprise
Bringing the JAMstack to the Enterprise
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

WordCamp Montreal 2016 WP-API + React with server rendering

  • 1. WP-API + React with server rendering + =
  • 2. Developer and teacher Co-founder of DecodeMTL Where to find me; github.com/ziad-saab @ZiadDotHTML decodemtl.com Hello! I am Ziad Saab
  • 3. WARNING This presentation is full of cats and code. #WordCatMTL
  • 4. lides and source code Slides French: ziad.cc/wcmtl-2016-fr.html English: ziad.cc/wcmtl-2016-en.html Source c ode github.com/ziad-saab/decodemtl-wp-frontend github.com/nyanofthemoon/decodemtl-wp-theme github.com/nyanofthemoon/recursive-acf-to-wp-rest-api github.com/nyanofthemoon/decodemtl-api
  • 5. eam Paule Lepage Backend + Proxy API Lucas Lemonnier Design + SASS Ziad Saab Frontend
  • 6. tructure of the talk 1.WordPress and the REST API 2.Overview of WP-API + React stack 3.Lessons learned: a.Metadata and technical SEO b.Async data loading c.How to manage i18n? 4.Conclusions
  • 7. iny timeline ▷ Founded DecodeMTL in 2014 ▷ Static website — HTML, CSS, JS ▷ Jekyll generates the site’s pages ▷ Yay! No backend! ▷ Mid-2015: need new site ▷ More dynamic and content-based ▷ Content ⇒ CMS ⇒ WordPress ▷ Dynamic ⇒ AJAX/SPA ⇒ React
  • 8. Inconvenients ▷ The theme is attached to backend ▷ Monolithic structure ▷ “The Loop” ▷ Have to use PHP for frontend ordPress... Advantages ▷ Free and open-source CMS ▷ Community and plugins ▷ Familiar/popular admin tool ▷ Custom post types ▷ Custom fields with ACF ▷ Languages management with Polylang or WPML
  • 9. ow to keep only the advantages? { "author": 1, "comment_status": "open", "content": { "rendered": "<p>Hello World!</p>n" }, "date": "2016-06-29T13:53:49", "date_gmt": "2016-06-29T13:53:49", "excerpt": { "rendered": "<p>Hello World!</p>n" }, "featured_media": 0, "format": "standard", "id": 29, "link": "http://decodemtl.com/...", "modified": "2016-06-29T13:53:49", "ping_status": "open", "slug": "hello-world", "slug_en": "hello-world", "slug_fr": "bonjour-monde", "tags": [], "title": { "rendered": "First Post" }, "type": "post" }
  • 10. { "author": 1, "comment_status": "open", "content": { "rendered": "<p>Hello World!</p>n" }, "date": "2016-06-29T13:53:49", "date_gmt": "2016-06-29T13:53:49", "excerpt": { "rendered": "<p>Hello World!</p>n" }, "featured_media": 0, "format": "standard", "id": 29, "link": "http://decodemtl.com/...", "modified": "2016-06-29T13:53:49", "ping_status": "open", "slug": "hello-world", "slug_en": "hello-world", "slug_fr": "bonjour-monde", "tags": [], "title": { "rendered": "First Post" }, "type": "post" } I SHOULD BUY A WP-API... ow to keep only the advantages?
  • 11. rchitecture WP-API + React Backend/ Data Template API Proxy
  • 12. <!doctype html> <html> <head> <meta charset="utf-8"> <title>SUPERBlog!</title> </head> <body> <div id="app"> <!-- i can haz content? --> </div> <script src="app.js"></script> </body> </html> erver rendering: sans
  • 13. erver rendering 101 GET /fr/cours/html-css HTTP/1.1 User-Agent: firefox Accept-Language: fr, en;q=0.7 ... ExpressJS server with /* route URL passed to react-router which returns tree of components Tree of components passed to redux-connect which uses Promise to wait for all data to be loaded Page data is loaded to a global store with the help of redux. react-dom/server renders the tree of components and react- redux injects store data as props HTTP/1.1 200 OK Date: Wed, 20 Jan 2038 16:19:42 GMT Content-Type: text/html Content-Length: … <!doctype html> <html> <head> <title><!--react-helmet title--></title> <!--meta tags I CAN HAZ SEOS??--> </head> <body> <div id=”app”><!-- react-dom --></div> <script src=”app.js”></script> <script><!--window.REDUX_STATE--></script> </body> </html>
  • 14. Partagé 850+ Server 100 Client 50 Ines of code I LIKE MATH... IT MAKES PEOPLE CRY.
  • 15. etadata and technical SEO react-helmet manages the <head>
  • 16. <Helmet defaultTitle="DecodeMTL" titleTemplate="%s | DecodeMTL" meta={[ {charset: 'utf-8'}, {property: 'og:site_name', content: '...'}, ... ]} /> <Helmet title={this.props.post.title} /> etadata and technical SEO - front
  • 17. const head = Helmet.rewind(); const title = head.title.toString(); // <title>Web Dev | DecodeMTL</title> const meta = head.meta.toString(); // <meta charset="utf-8"><meta ...> ... etadata and technical SEO - back
  • 18. polylang manages posts and CPT translation in WordPress react-intl manages string translation in the templates nternationalization
  • 19. nternationalization - WordPress function decodemtl_polylang_slugs($post) { $language = $polylang->model->get_post_language($post->ID); $current = $language->slug; $currentSlug = $post->post_name; $oppositeSlug = ''; $opposite = ('en' === $current) ? 'fr' : 'en'; $oppositePostId = pll_get_post($post->ID, $opposite); if ($oppositePostId) { $oppositePost = get_post($oppositePostId); $oppositeSlug = $oppositePost->post_name; } return array( 'slug_' . $current => $currentSlug, 'slug_' . $opposite => $oppositeSlug ); }
  • 20. nternationalization - <head> <link rel="alternate" hreflang="fr" href="https://..."> PARLEZ-VOUS FRANÇAIS?
  • 21. nternationalization - routes React <Route path="/" component={App}> <Route path="fr" onEnter={() => dispatch(switchLang('fr'))}> <IndexRoute component={Home}/> <Route path="blogue" component={Blog} /> <Route path="blogue/:slug" component={BlogPost} /> <Route path="cours" component={Courses} /> <Route path="cours/:slug" component={CoursePage} /> <Route path=":slug" component={SinglePage} /> </Route> <Route onEnter={() =>dispatch(switchLang('en'))}> <IndexRoute component={Home}/> <Route path="blog" component={Blog} /> <Route path="blog/:slug" component={BlogPost} /> <Route path="courses" component={Courses} /> <Route path="courses/:slug" component={CoursePage} /> <Route path=":slug" component={SinglePage} /> </Route> </Route>
  • 23. nternationalisation - translation module.exports = { "homePage.title": "Bienvenue à DecodeMTL", "homePage.courses": "Nos cours", "coursePage.instructor": "Votre instructeur", "coursePage.schedule": "Horaire du cours", "coursePage.sessions": "Prochaines sessions", "loadingBox.text": "Chargement...", "notFoundPage.title": "404 Non Trouvé!", ... };
  • 24. TTP and AJAX isomorphic-fetch manages AJAX in front and HTTP requests in back
  • 26. TTP and AJAX redux-connect manages the data fetching synchronization
  • 27. TTP and AJAX - front @asyncConnect([ { deferred: true, promise: function(opt) { var slug = opt.params.slug; return opt.store.dispatch(loadCourse(slug)); } } ]) class BlogPost extends React.Component { render() {...} }
  • 28. TTP and AJAX - back app.get('/*', (req, res) => { const memHistory = createHistory(req.url); const store = makeStore(memHistory); const routes = require('./routes'); const options = {history: memHistory, routes: routes, location: req.url}; match(options, function(err, redirectLocation, renderProps) { if (redirectLocation) { res.redirect(redirectLocation.pathname + redirectLocation.search); } else if (renderProps) { loadOnServer({...renderProps, store}) .then(function() { const html = ReactDOM.renderToString( <Provider store={store} key="provider"> <ReduxAsyncConnect {...renderProps} /> </Provider> ); const head = Helmet.rewind(); const title = head.title.toString(); const meta = head.meta.toString(); const link = head.link.toString(); const finalState = store.getState(); res.render('index', {html, title, meta, link, finalState}); }); } }); });
  • 29. emo?
  • 30. onclusions ▷ Using React for a WordPress theme gives you the advantages of SPA but also its inconvenients ▷ Server rendering negates some inconvenients like the lack of content and slow loading times ▷ Server rendering doesn’t require more work if we add more pages/features — scalable ▷ This method is a bit overkill for a simple blog. A small ExpressJS app would suffice if you want to stay in JS.