Slide 1

Slide 1 text

Perl Ͱ΋ React.js ͷ server-side rendering ͕͍ͨ͠ʂ Gotanda.pm #5 @zoncoen

Slide 2

Slide 2 text

ͱ͍͏ਓ΋͍Δ͔΋͠Εͳ͍ ʢੈք͸޿͍ʣ

Slide 3

Slide 3 text

Ͱ͖ΔΑ

Slide 4

Slide 4 text

What is React.js • JavaScript view library • Facebook

Slide 5

Slide 5 text

Why server-side rendering? • ॳظϩʔυ࣌ؒͷվળ • SEO ! React.js ͸ରԠͯ͠Δ

Slide 6

Slide 6 text

• React.renderToString() • ReactElement ͷ initial HTML Λฦ͢ with Node.js web server React.renderToString(React.createElement(MyClass, {data: data}));

Slide 7

Slide 7 text

with other languages • Ruby (on Rails): react-rails ! • Python: python-react ! → ֤ݴޠ͔Β JavaScript ͷؔ਺Λ࣮ߦ react_component('MyComponent', {data: data}, {prerender: true}) render_component('my-component.jsx', {'data': data}, to_static_markup=true)

Slide 8

Slide 8 text

Perl Ͱ΋΍ΕΔʢ͸ͣ | ΂͖ʣ

Slide 9

Slide 9 text

How to implement • renderToString() ͷ࣮ߦ݁Ռ͕͋Ε͹͍͍ → Perl ͔Β JavaScript ͷؔ਺Λ࣮ߦ

Slide 10

Slide 10 text

JavaScript::V8 • Perl interface to the V8 JavaScript engine • Latest version released on 28 Dec 2012 … ! • ͱΓ͋͑ͣ V8 v3.14.5.8 Ͱಈ͘͜ͱΛ֬ೝ

Slide 11

Slide 11 text

Example #!/usr/bin/env perl use strict; use warnings; use utf8; ! use JavaScript::V8; ! my $context = JavaScript::V8::Context->new(); ! my $result = $context->eval(q| (function () { return 'Hello, JavaScript world!'; })(); |); ! print "$result\n";

Slide 12

Slide 12 text

Demo https://github.com/zoncoen-sample/reactjs_server-side- rendering_with_perl