SlideShare a Scribd company logo
SSR
What is SSR ?
Server side rendering review
Server side rendering review
Main steps to implement SSR
Server side:
1. Receive request from client
2. Request parsing on server
3. Rendering client application on server
4. Inserts the serialized state of the application into rendered HTML (if there is a state)
5. Setting Headers
6. Submitting rendered HTML code
Client side:
1. Sending a request to the server
2. Getting rendered HTML code.
3. Request to download the rest of the statics and js bundles.
4. Deserealization of saved application state.
5. Creating a local state based on what we spars.
6. Application work as usual.
Additional info
1. The state of the application is saved to the global JS variable
window.__ STATE__, which will be read on the client.
2. When developing SSR it is convenient to use cookies instead of localStorage.
3. Routing on the client and server must match.
4. On the server, as well as on the client, you can perform asynchronous data
loading and substitute them into HTML or application state.
CSR
SSR
SSR pros:
1. SEO support for SPA.
2. Fast data rendering on the client.
3. Excellent work on weak devices.
4. Less data transfer costs, faster work on a slow
connection.
SSR cons:
1. Decreased performance on weak servers.
2. High resource costs on the server side.
3. Difficulty to develop.
4. Long development time.
Prerendering
Rendering using HTML parsers.
Prerenderers
● Use NodeJS as the main platform (in the following
examples).
● Use headless browsers such as: Puppeteer, JSDOM,
Selenium, WebdriverIO, PhantomJS, etc.
● Render the page in a headless browser and send the
result to the client.
● Do not need duplicate client routing.
Prerendering implementations
● prerender.io is an open source service that allows you to organize the
redirection of traffic from crawlers to a special browser that executes
javascript code and returns a static html page.
● PhantomJS is used as a browser.
● Price from $ 15 to $ 65
RenderjS.io
● renderjs.io is a cloud based service that works similarly to prerender.io, but
works fast.
● Does not use cache.
● Uses the latest version of Chromium.
● Price from $ 10 to $ 40
prerender-node
● express.js middleware for pre-rendering.
● Free.
● There is a customization of processing routes.
● All on your shoulders.
prerender-spa-plugin
● Webpack plugin for pre-rendering.
● Requires custom configuration routes.
● Free.
● Based on Puppeteer.
prerender-spa-plugin config example
Prerendering cons:
● Good pre-rendering is paid.
● Slow on large projects.
● The complexity of managing caching.
● The difficulty in debugging errors on the server.
● Less flexibility and scalability than with SSR.
When to use prerendering
● Small projects.
● Small amount of time / resources for project development.
● No complex common logic between the client and the
server.
● Small amount of changeable data
SSR
for popular SPA frameworks
● Based on the use of the @nguniversal/express-engine library.
● Works with @angular/platform-server, which provides server
implementation of DOM, Ajax, and many other browser features.
● Official example: https://github.com/angular/universal-starter.
Angular Universal
SSR Vue Tools
SSR + Vue Tools
1. Install vue-server-renderer.
2. Create a renderer:
const renderer = require ('vue-server-renderer').createRenderer().
3. Render the vue application with renderToString:
renderer.renderToString(app, err, html).
4. Sending content to the client.
More on: ssr.vuejs.org
On October 25, 2016, the zeit.co team announced Next.js,
a React application framework with server rendering.
A few hours after this announcement Nuxt.js was born.
Nuxt setup
1. npx create-nuxt-app app-name
2. Choose UI framework
3. Select eslint, prettier, npm / yarn, etc.
4. The rest of the development and configuration is similar to
Next.js
ReactDOMServer
SSR + React Tools (v16)
● Improved server rendering performance
● Streaming support
● Support for custom attribute elements with SSR
● Instead of render () client added hydrate ()
● While at SSR, the Error boundaries and portals are not fully
supported.
ReactDOMServer methods
● renderToString - renders the react component in an html string.
● renderToStaticMarkup is the same, but does not add the react attributes for internal
use.
● renderToNodeStream - returns a stream in binary format in utf-8 coding, with
rendered HTML. This method is supported only on the server side.
● renderToStaticNodeStream is the same difference as renderToStaticMarkup from
renderToString.
Custom Node.js server
+
React Tools
Server side rendering review
1. Create a Node.js server on Express or Koa (whatever you
like).
2. We create a static server that gives static.
3. At the root endpoint we hang the listener, which calls
renderToString (app) and gives HTML to the client.
Custom SSR: server
On the client, we render our application using the hydrate()
method
Custom SSR: client
1. We add react-router, on client side (browser-router).
2. On the server side, we need to use StaticRouter, in which
we wrap our root component and pass req.url to this
router in the location parameter.
Custom SSR: router
Server side rendering review
Server side rendering review
1. Initialize redux store.
2. Get store snapshot.
3. Serialize it into a variable and pass it to a
window.__ REDUX_DATA__ field.
4. Send content to the client.
Custom SSR: Redux on server
Server side rendering review
Server side rendering review
1. Check whether we are on the client.
2. Retrieve and deserialize a snapshot of a window from
window .__ REDUX_DATA__.
3. Pass the received state to createStore (initialState)
4. Transfer created store to provider.
Custom SSR: Redux on client
Server side rendering review
1. We use mobx and mobx-state-tree
2. Previously, mobx could not be used with SSR.
3. MST handles data trees.
4. Data is serialized using snapshots.
Custom SSR: Mobx
1. We check the server or client.
2. Create a store.
3. We receive snapshot through getSnapshot ().
4. Save the snapshot in window.__ MOBX_STATE__.
5. We send data to the client.
Custom SSR: Mobx server
Custom SSR: Mobx client
1. We check the server or client.
2. Get snapshot from window.__ MOBX_STATE__.
3. We transfer snapshot to function-generator.
4. In the generator, apply to the snapshot via
applySnapshot().
5. We transfer stor to provider.
Server side rendering review
Server side rendering review
Server side rendering review
MST with custom Node.js server
Server side rendering review
Server side rendering review
1. We use the fetch-component-data package.
2. We mark in each component what data should be
provided before rendering.
3. On the server we get all the data for the components
and in the callback we render the application.
Custom SSR: Async data fetch on server
Server side rendering review
Server side rendering review
1. helmet helps to quickly set up a head for pages.
2. On the client we use the component Helmet.
3. On the server, use the renderStatic() function.
Custom SSR: Helmet
Server side rendering review
Server side rendering review
Next.js
React framework for server side rendering
1. SSR works from the default configuration.
2. Automatic code splitting for each page.
3. Simple and clear routing.
4. Webpack with HMR out of the box.
5. Ability to add your ExpressJS server.
6. Ability to expand webpack and babel config.
Next.js intro
1. mkdir hello-next
2. cd hello-next
3. npm init -y
4. npm install --save react react-dom next
5. mkdir pages
Next.js installation
Next.js simple folder structure
Next.js pages
1. <Link />
2. Router from next/router
3. href
Next.js routes transitions approaches
Next.js components
1. Next.js by default works with query (page? Id = 100)
2. For routes with parameters, the next option is to use a
custom node.js server.
3. We can also use next-routes
Next.js dynamic routing
Server side rendering review
next-routes routes
next-routes server
Next.js scripts with custom server
Further project configuration is up to you
Next.js: changing babel config
1. We could change web pack config in next.config.js.
2. Setting loaders and palins is different from the usual
settings in webpack.config.js.
3. To add loaders and plugins, it is convenient to use
custom packages like @zeit/next-stylus, @zeit/next-css,
etc.
Next.js: changing web pack config
Next.js webpack custom packages
Next.js webpack plugins
Next.js webpack configuration
1. Getting server-side asynchronous data is performed using
the getInitialProps function.
2. This is a static page function in which we can prepare a
page component before rendering and provide all the
necessary resources for its operation.
Next.js async data fetch
Server side rendering review
1. Rendered on the server.
2. Used to change the DOM on the server.
3. Often used to implement server-side css-in-js.
4. Support styled-components, emotion, glamorous,
styled-jsx comes next.js out of the box.
Next.js custom document
Server side rendering review
1. Preserving the layout between page transitions.
2. Save the application state.
3. To handle errors using componentDidCatch.
4. Adding data to pages (for example, useful when used
with graphql).
Next.js custom App
Server side rendering review
1. We check on the server or on the client.
2. If on the server, then we initialize the store.
3. If on the client, then we check window.__ NEXT_REDUX_STORE__, if it exists,
then we initialize the stop with this snapshot, if not, from scratch.
4. This all happens in the PHOK, with which we wrap our root component of the page,
check and initialize everything in the familiar getInitialProps.
5. Then we transfer the store to the provider.
Next.js + Redux
Server side rendering review
Server side rendering review
1. Configuration is similar to adding mobx and mst to
custom node.js ssr.
2. Init stores.
3. Serialize stores from snapshots.
4. Deserialize snapshots on the client.
5. Create stores from snapshots on the client.
Next.js + Mobx & MST
After.js
If NextJS and React Router had a baby ...
After.js: what can be changed in Next.js?
1. Routes are just components and have no relation to the
folder structure. Static configs are better.
2. GetInitialProps from Next.js is a great idea.
3. Dividing code based on routes should be easy.
4. Route based transitions and data preloading should be
easier.
After.js: we can use RR4
After.js: current state
1. It was quite ambitious, but did not achieve the same
popularity as Next.js.
2. Now a small amount of PR and issues.
3. The community is much smaller than Next.js’s community.
4. The problems that After.js tried to solve are already solved
(or being solved) by Next.js.
5. Next.js ⭐️33860 VS After.js ⭐️2864
1. Carefully with launch scripts for selling, be sure to NODE_ENV = production,
otherwise 500 on-demand-entries-ping
2. It is better to run via /usr/bin/node server (with custom server and supervisor).
3. User react-routes for convenient configuration of dynamic routes
4. Use universal-cookie-express, compression with your custom server.
5. For environment variables it is better to use dotenv-webpack, there are some
problems with webpack.DefinePlugin and Next.js.
6. For graphql there is an example with Apollo in the official repository.
Next.js: additional
RESUME
What should you choose?
1. Minimum effort - prerendering.
2. Maximum setting “for yourself” - custom nodejs
server + SSR.
3. Convenience, support and community - NextJS.
What should you choose?
Q&A
morzhanov

More Related Content

What's hot (20)

PPTX
Next.js vs React | what to choose for frontend development_
ForceBolt
 
PPTX
Node.js Express
Eyal Vardi
 
PPTX
React hooks
Assaf Gannon
 
PDF
Routing in NEXTJS.pdf
AnishaDahal5
 
PDF
NextJS - Online Summit for Frontend Developers September 2020
Milad Heydari
 
PPTX
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
ODP
Introduction to ReactJS
Knoldus Inc.
 
PDF
Expressjs
Yauheni Nikanovich
 
PDF
Universal React apps in Next.js
🐕 Łukasz Ostrowski
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
Understanding react hooks
Samundra khatri
 
PDF
NodeJS for Beginner
Apaichon Punopas
 
PDF
Use Node.js to create a REST API
Fabien Vauchelles
 
PDF
React js
Rajesh Kolla
 
PDF
An introduction to Vue.js
Javier Lafora Rey
 
PPTX
React hooks
Ramy ElBasyouni
 
PPTX
[Final] ReactJS presentation
洪 鹏发
 
PPTX
Introduction to Node.js
AMD Developer Central
 
PDF
An introduction to React.js
Emanuele DelBono
 
Next.js vs React | what to choose for frontend development_
ForceBolt
 
Node.js Express
Eyal Vardi
 
React hooks
Assaf Gannon
 
Routing in NEXTJS.pdf
AnishaDahal5
 
NextJS - Online Summit for Frontend Developers September 2020
Milad Heydari
 
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
Introduction to ReactJS
Knoldus Inc.
 
Universal React apps in Next.js
🐕 Łukasz Ostrowski
 
React + Redux Introduction
Nikolaus Graf
 
ReactJS presentation
Thanh Tuong
 
Understanding react hooks
Samundra khatri
 
NodeJS for Beginner
Apaichon Punopas
 
Use Node.js to create a REST API
Fabien Vauchelles
 
React js
Rajesh Kolla
 
An introduction to Vue.js
Javier Lafora Rey
 
React hooks
Ramy ElBasyouni
 
[Final] ReactJS presentation
洪 鹏发
 
Introduction to Node.js
AMD Developer Central
 
An introduction to React.js
Emanuele DelBono
 

Similar to Server side rendering review (20)

PDF
JSFest 2019: Technology agnostic microservices at SPA frontend
Vlad Fedosov
 
PPTX
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JSFestUA
 
PDF
Reactive Application Using METEOR
NodeXperts
 
PDF
How to upgrade to MongoDB 4.0 - Percona Europe 2018
Antonios Giannopoulos
 
PPTX
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
PPTX
Reactive application using meteor
Sapna Upreti
 
PPTX
Web and Android App Development
Gaurav Gopal Gupta
 
PDF
Webrender 1.0
Daosheng Mu
 
PDF
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
seo18
 
PDF
Day In A Life Of A Node.js Developer
Edureka!
 
PDF
Day in a life of a node.js developer
Edureka!
 
PDF
Spring MVC Framework
Hùng Nguyễn Huy
 
PDF
Bt0083 server side programing
Techglyphs
 
DOCX
unit 2 of Full stack web development subject
JeneferAlan1
 
ODP
The secret life of a dispatcher (Adobe CQ AEM)
Venugopal Gummadala
 
PDF
Tips and Tricks For Faster Asp.NET and MVC Applications
Sarvesh Kushwaha
 
PPTX
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 
JSFest 2019: Technology agnostic microservices at SPA frontend
Vlad Fedosov
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JSFestUA
 
Reactive Application Using METEOR
NodeXperts
 
How to upgrade to MongoDB 4.0 - Percona Europe 2018
Antonios Giannopoulos
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
Reactive application using meteor
Sapna Upreti
 
Web and Android App Development
Gaurav Gopal Gupta
 
Webrender 1.0
Daosheng Mu
 
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
seo18
 
Day In A Life Of A Node.js Developer
Edureka!
 
Day in a life of a node.js developer
Edureka!
 
Spring MVC Framework
Hùng Nguyễn Huy
 
Bt0083 server side programing
Techglyphs
 
unit 2 of Full stack web development subject
JeneferAlan1
 
The secret life of a dispatcher (Adobe CQ AEM)
Venugopal Gummadala
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Sarvesh Kushwaha
 
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 
Ad

Recently uploaded (20)

PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPTX
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
Dealing with JSON in the relational world
Andres Almiray
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Ad

Server side rendering review

  • 1. SSR
  • 5. Main steps to implement SSR
  • 6. Server side: 1. Receive request from client 2. Request parsing on server 3. Rendering client application on server 4. Inserts the serialized state of the application into rendered HTML (if there is a state) 5. Setting Headers 6. Submitting rendered HTML code
  • 7. Client side: 1. Sending a request to the server 2. Getting rendered HTML code. 3. Request to download the rest of the statics and js bundles. 4. Deserealization of saved application state. 5. Creating a local state based on what we spars. 6. Application work as usual.
  • 8. Additional info 1. The state of the application is saved to the global JS variable window.__ STATE__, which will be read on the client. 2. When developing SSR it is convenient to use cookies instead of localStorage. 3. Routing on the client and server must match. 4. On the server, as well as on the client, you can perform asynchronous data loading and substitute them into HTML or application state.
  • 9. CSR
  • 10. SSR
  • 11. SSR pros: 1. SEO support for SPA. 2. Fast data rendering on the client. 3. Excellent work on weak devices. 4. Less data transfer costs, faster work on a slow connection.
  • 12. SSR cons: 1. Decreased performance on weak servers. 2. High resource costs on the server side. 3. Difficulty to develop. 4. Long development time.
  • 14. Prerenderers ● Use NodeJS as the main platform (in the following examples). ● Use headless browsers such as: Puppeteer, JSDOM, Selenium, WebdriverIO, PhantomJS, etc. ● Render the page in a headless browser and send the result to the client. ● Do not need duplicate client routing.
  • 16. ● prerender.io is an open source service that allows you to organize the redirection of traffic from crawlers to a special browser that executes javascript code and returns a static html page. ● PhantomJS is used as a browser. ● Price from $ 15 to $ 65
  • 17. RenderjS.io ● renderjs.io is a cloud based service that works similarly to prerender.io, but works fast. ● Does not use cache. ● Uses the latest version of Chromium. ● Price from $ 10 to $ 40
  • 18. prerender-node ● express.js middleware for pre-rendering. ● Free. ● There is a customization of processing routes. ● All on your shoulders.
  • 19. prerender-spa-plugin ● Webpack plugin for pre-rendering. ● Requires custom configuration routes. ● Free. ● Based on Puppeteer.
  • 21. Prerendering cons: ● Good pre-rendering is paid. ● Slow on large projects. ● The complexity of managing caching. ● The difficulty in debugging errors on the server. ● Less flexibility and scalability than with SSR.
  • 22. When to use prerendering ● Small projects. ● Small amount of time / resources for project development. ● No complex common logic between the client and the server. ● Small amount of changeable data
  • 23. SSR for popular SPA frameworks
  • 24. ● Based on the use of the @nguniversal/express-engine library. ● Works with @angular/platform-server, which provides server implementation of DOM, Ajax, and many other browser features. ● Official example: https://github.com/angular/universal-starter. Angular Universal
  • 26. SSR + Vue Tools 1. Install vue-server-renderer. 2. Create a renderer: const renderer = require ('vue-server-renderer').createRenderer(). 3. Render the vue application with renderToString: renderer.renderToString(app, err, html). 4. Sending content to the client. More on: ssr.vuejs.org
  • 27. On October 25, 2016, the zeit.co team announced Next.js, a React application framework with server rendering. A few hours after this announcement Nuxt.js was born.
  • 28. Nuxt setup 1. npx create-nuxt-app app-name 2. Choose UI framework 3. Select eslint, prettier, npm / yarn, etc. 4. The rest of the development and configuration is similar to Next.js
  • 30. SSR + React Tools (v16) ● Improved server rendering performance ● Streaming support ● Support for custom attribute elements with SSR ● Instead of render () client added hydrate () ● While at SSR, the Error boundaries and portals are not fully supported.
  • 31. ReactDOMServer methods ● renderToString - renders the react component in an html string. ● renderToStaticMarkup is the same, but does not add the react attributes for internal use. ● renderToNodeStream - returns a stream in binary format in utf-8 coding, with rendered HTML. This method is supported only on the server side. ● renderToStaticNodeStream is the same difference as renderToStaticMarkup from renderToString.
  • 34. 1. Create a Node.js server on Express or Koa (whatever you like). 2. We create a static server that gives static. 3. At the root endpoint we hang the listener, which calls renderToString (app) and gives HTML to the client. Custom SSR: server
  • 35. On the client, we render our application using the hydrate() method Custom SSR: client
  • 36. 1. We add react-router, on client side (browser-router). 2. On the server side, we need to use StaticRouter, in which we wrap our root component and pass req.url to this router in the location parameter. Custom SSR: router
  • 39. 1. Initialize redux store. 2. Get store snapshot. 3. Serialize it into a variable and pass it to a window.__ REDUX_DATA__ field. 4. Send content to the client. Custom SSR: Redux on server
  • 42. 1. Check whether we are on the client. 2. Retrieve and deserialize a snapshot of a window from window .__ REDUX_DATA__. 3. Pass the received state to createStore (initialState) 4. Transfer created store to provider. Custom SSR: Redux on client
  • 44. 1. We use mobx and mobx-state-tree 2. Previously, mobx could not be used with SSR. 3. MST handles data trees. 4. Data is serialized using snapshots. Custom SSR: Mobx
  • 45. 1. We check the server or client. 2. Create a store. 3. We receive snapshot through getSnapshot (). 4. Save the snapshot in window.__ MOBX_STATE__. 5. We send data to the client. Custom SSR: Mobx server
  • 46. Custom SSR: Mobx client 1. We check the server or client. 2. Get snapshot from window.__ MOBX_STATE__. 3. We transfer snapshot to function-generator. 4. In the generator, apply to the snapshot via applySnapshot(). 5. We transfer stor to provider.
  • 50. MST with custom Node.js server
  • 53. 1. We use the fetch-component-data package. 2. We mark in each component what data should be provided before rendering. 3. On the server we get all the data for the components and in the callback we render the application. Custom SSR: Async data fetch on server
  • 56. 1. helmet helps to quickly set up a head for pages. 2. On the client we use the component Helmet. 3. On the server, use the renderStatic() function. Custom SSR: Helmet
  • 59. Next.js React framework for server side rendering
  • 60. 1. SSR works from the default configuration. 2. Automatic code splitting for each page. 3. Simple and clear routing. 4. Webpack with HMR out of the box. 5. Ability to add your ExpressJS server. 6. Ability to expand webpack and babel config. Next.js intro
  • 61. 1. mkdir hello-next 2. cd hello-next 3. npm init -y 4. npm install --save react react-dom next 5. mkdir pages Next.js installation
  • 64. 1. <Link /> 2. Router from next/router 3. href Next.js routes transitions approaches
  • 66. 1. Next.js by default works with query (page? Id = 100) 2. For routes with parameters, the next option is to use a custom node.js server. 3. We can also use next-routes Next.js dynamic routing
  • 70. Next.js scripts with custom server
  • 73. 1. We could change web pack config in next.config.js. 2. Setting loaders and palins is different from the usual settings in webpack.config.js. 3. To add loaders and plugins, it is convenient to use custom packages like @zeit/next-stylus, @zeit/next-css, etc. Next.js: changing web pack config
  • 77. 1. Getting server-side asynchronous data is performed using the getInitialProps function. 2. This is a static page function in which we can prepare a page component before rendering and provide all the necessary resources for its operation. Next.js async data fetch
  • 79. 1. Rendered on the server. 2. Used to change the DOM on the server. 3. Often used to implement server-side css-in-js. 4. Support styled-components, emotion, glamorous, styled-jsx comes next.js out of the box. Next.js custom document
  • 81. 1. Preserving the layout between page transitions. 2. Save the application state. 3. To handle errors using componentDidCatch. 4. Adding data to pages (for example, useful when used with graphql). Next.js custom App
  • 83. 1. We check on the server or on the client. 2. If on the server, then we initialize the store. 3. If on the client, then we check window.__ NEXT_REDUX_STORE__, if it exists, then we initialize the stop with this snapshot, if not, from scratch. 4. This all happens in the PHOK, with which we wrap our root component of the page, check and initialize everything in the familiar getInitialProps. 5. Then we transfer the store to the provider. Next.js + Redux
  • 86. 1. Configuration is similar to adding mobx and mst to custom node.js ssr. 2. Init stores. 3. Serialize stores from snapshots. 4. Deserialize snapshots on the client. 5. Create stores from snapshots on the client. Next.js + Mobx & MST
  • 87. After.js If NextJS and React Router had a baby ...
  • 88. After.js: what can be changed in Next.js? 1. Routes are just components and have no relation to the folder structure. Static configs are better. 2. GetInitialProps from Next.js is a great idea. 3. Dividing code based on routes should be easy. 4. Route based transitions and data preloading should be easier.
  • 89. After.js: we can use RR4
  • 90. After.js: current state 1. It was quite ambitious, but did not achieve the same popularity as Next.js. 2. Now a small amount of PR and issues. 3. The community is much smaller than Next.js’s community. 4. The problems that After.js tried to solve are already solved (or being solved) by Next.js. 5. Next.js ⭐️33860 VS After.js ⭐️2864
  • 91. 1. Carefully with launch scripts for selling, be sure to NODE_ENV = production, otherwise 500 on-demand-entries-ping 2. It is better to run via /usr/bin/node server (with custom server and supervisor). 3. User react-routes for convenient configuration of dynamic routes 4. Use universal-cookie-express, compression with your custom server. 5. For environment variables it is better to use dotenv-webpack, there are some problems with webpack.DefinePlugin and Next.js. 6. For graphql there is an example with Apollo in the official repository. Next.js: additional
  • 93. 1. Minimum effort - prerendering. 2. Maximum setting “for yourself” - custom nodejs server + SSR. 3. Convenience, support and community - NextJS. What should you choose?