Slide 1

Slide 1 text

THERE AND BACK AGAIN, A DEVELOPER'S TALE BY JACK LENOX

Slide 2

Slide 2 text

THE FACTS > Using websites often sucks. > Connections can be crappy. > Page load times can be slow. > Not always a continuous user experience.

Slide 3

Slide 3 text

THE STATE OF JAVASCRIPT > Google Play/Docs > Instagram > UCLA School of the Arts & Architecture

Slide 4

Slide 4 text

JAVASCRIPT & WORDPRESS (PLUS REST API) > Quartz > ustwo > Calypso

Slide 5

Slide 5 text

SINGLE-PAGE APPLICATIONS

Slide 6

Slide 6 text

SINGLE-PAGE APPLICATIONS > Historically, well criticised. > Have been maturing over a long period of time now. > Not necessarily suited to every case, but more maligned than they deserve.

Slide 7

Slide 7 text

WELL-DOCUMENTED DOWNSIDES > Search Engine Optimisation > Client/server code partitioning > Browser history > Analytics > Speed of initial load

Slide 8

Slide 8 text

BUT HANG ON? > HTML5 > HTTP/2 > Node.js

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

WITHOUT JAVASCRIPT, THINGS ARE GETTING HARDER > Service Worker. > Push notifications. > User expectations.

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

NICE, BUT IS IT RESPONSIVE?

Slide 13

Slide 13 text

MARRYING WORDPRESS AND SINGLE-PAGE APPLICATIONS?

Slide 14

Slide 14 text

SINGLE-PAGE THEMES?

Slide 15

Slide 15 text

LET'S RECAP The problems with single-page applications: > Search Engine Optimisation > Client/server code partitioning > Browser history > Analytics > Speed of initial load

Slide 16

Slide 16 text

THE PATH TO ENLIGHTENMENT Search Engine Optimisation Client/server code partitioning Browser history Analytics Speed of initial load

Slide 17

Slide 17 text

THE PATH TO ENLIGHTENMENT Search Engine Optimisation Client/server code partitioning Browser history Analytics Speed of initial load

Slide 18

Slide 18 text

BROWSER HISTORY AND ANALYTICS History API1: var state = { 'post_id': 1234 }; var title = 'A Day of Rest'; var url = 'a-day-of-rest'; history.pushState( state, title, url ); 1 For more information on this, check out the MDN History API docs.

Slide 19

Slide 19 text

THE PATH TO ENLIGHTENMENT Search Engine Optimisation Client/server code partitioning Speed of initial load

Slide 20

Slide 20 text

THE PATH TO ENLIGHTENMENT Search Engine Optimisation Client/server code partitioning Speed of initial load

Slide 21

Slide 21 text

CLIENT/SERVER CODE PARTITIONING Handlebars or Mustache:

{{the_title}}

{{the_content}}

Slide 22

Slide 22 text

CLIENT/SERVER CODE PARTITIONING React:

{ this.props.title }

{ this.props.content }

Slide 23

Slide 23 text

THE PATH TO ENLIGHTENMENT Search Engine Optimisation Speed of initial load

Slide 24

Slide 24 text

THE PATH TO ENLIGHTENMENT Search Engine Optimisation Speed of initial load

Slide 25

Slide 25 text

SEARCH ENGINE OPTIMISATION Google, Bing and DuckDuckGo can already crawl JS rendered sites.

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

THE PATH TO ENLIGHTENMENT Speed of initial load

Slide 31

Slide 31 text

THE PATH TO ENLIGHTENMENT Speed of initial load

Slide 32

Slide 32 text

SPEED OF INITIAL LOAD Automatically generate PHP from your JS: var markup = ""; markup = markup.replace( /the_title/gi, '' ); markup = markup.replace( /the_content/gi, '' ); fs.writeFileSync( 'single.php', markup );

Slide 33

Slide 33 text

SO HOW TO PROCEED? No more excuses. Just do it!

Slide 34

Slide 34 text

ಠ_ಠ

Slide 35

Slide 35 text

BUT WAIT, THERE'S MORE!

Slide 36

Slide 36 text

DON'T RUN AJAX ON EVERY PAGE

Slide 37

Slide 37 text

BOOTSTRAP // functions.php $bootstrap = array(); global $wp_query; while ( $wp_query->have_posts() ) { $wp_query->the_post(); $bootstrap[] = array( "id" => get_the_ID(), "title" => array( "rendered" => get_the_title() ) ); } $bootstrap_json = json_encode( $bootstrap ); wp_register_script( 'bs-script', ... ); wp_localize_script( 'bs-script', 'bootstrap_json', $bootstrap_json ); wp_enqueue_script( 'bs-script' );

Slide 38

Slide 38 text

WHAT ABOUT ALL THE OTHER OPTIONS?

Slide 39

Slide 39 text

LOCALISE ALL THE THINGS $permalink_structure = get_option( 'permalink_structure' ); $show_on_front = get_option( 'show_on_front' ); $page_on_front = get_option( 'page_on_front' );

Slide 40

Slide 40 text

FURTHER READING > github.com/humanmade/feelingrestfultheme > egghead.io/instructors/dan-abramov > github.com/ryelle/Anadama-React > github.com/Automattic/wp-calypso > (github.com/jacklenox) > themeshaper.com/2015/11/23/javascript-theme-tutorial/

Slide 41

Slide 41 text

THE END @jacklenox > automattic.com/work-with-us/