Lessons Learned from using in Production @PanJ
 Panjamapong Sermsawatsri June, 3 2017
 React Bangkok 2.0.0
 Pathumwan Institute of Technology
Panjamapong (PanJ) Sermsawatsri CTO at TakeMeTour
 Google Developer Expert in Web Technology @PanJ June, 3 2017
 React Bangkok 2.0.0
 Pathumwan Institute of Technology
Single-page Application
Single-page Application
1 HTTP(S) Request • DNS Lookup • TLS Handshaking • First Byte • Last Byte • If got redirect response (3xx), repeat step 1
Single-page Application
Single-page Application Static HTML
Single-page Application First paint starts here
Server-side Rendering (SSR)
 to the Rescue
Server-side Rendering Rendered HTML
Server-side Rendering First paint starts here Interaction is ready here
Server-side Rendering inline only used CSS
Server-side Rendering First paint starts here
Server-side Rendering Still long time-to-interact
Code Splitting
 to the Rescue
Code-splitting main.js home.js product.js about.js
Code-splitting prefetch in idle period time-to-interact
How to implement all of these? Code-spliting Inline Critical CSS Server-side Rendering Prefetching
comes with • Server-side rendering • Automatic code-splitting • Prefetch support • Inline critical CSS • Built-in routing
Next.js 2 is production-ready
But! There are few things you might need to know
Higher-order Component • Each page in Next.js is completely separated • You must use HOC to create a shared environment • Styles, Navbar, Redux, i18n, initalProps
styled-jsx Wow! template string literal!!!
styled-jsx Only this part can be templated
styled-jsx
Styling • Styled-jsx is painful if you are migrating component from previous project • You can use SCSS / postcss / cssnext to help reduce this pain • After P’Khame’ session, I recommend 
 styled-component
comes with • Server-side rendering • Automatic code-splitting • Prefetch support • Inline critical CSS • Built-in routing Optimized for SEO
 and landing pages
Migrating to
Optimizing Page Speed • Keep bundle small • Reduce first request load time
Optimizing Page Speed • Keep bundle small • Reduce first request load time
Keep bundle small • Home • Product Category • Product Detail • About Us • Dashboard • Settings • Checkout • Notifications SEO / Landing pages Non-SEO pages
Keep bundle small • Home • Product Category • Product Detail • About Us • Dashboard • Settings • Checkout • Notifications Legacy (?) React Site
Seamless routing between 2 apps Legacy /product/2 /dashboard
Optimizing Page Speed • Keep bundle small • Reduce first request load time
Reduce first request load time App API DB
Reduce first request load time App API DB
Static Caching
 to the rescue
Static Caching App API DB
Static Caching NEXT API DB L
Static Caching is Dangerous
Static Caching is Dangerous • Every request with same URL will respond the same content • Session / Login data must be retrieve in client- side via componentDidMount • Side-effect is not allowed in each request (E.g. counting page view from server-side)
NEXT API DB L Reduce first request load time
MISS
HIT
Kapook.com
GitHub
https://latency.apex.sh made by
 TJ Holowaychuk Global Latency Test Tool
Speed Matters 50% > 3 second to load. of users will drop is page takes
Let’s build not just cool but fast website
Wanna learn and build cool stuffs? We are hiring! Send your GitHub repo to 
 WantToWork@takemetour.com
Panjamapong Sermsawatsri @PanJ Q&A

Lessons Learned from Using Next.js in Production