SlideShare a Scribd company logo
SSR in NextJSModern Server-Side
Rendering elaboration
in NextJS
Challenges, performance, Tips & Tricks,
Deployment
Who I AmMilad Heydari
Full-Time Developer, Part-Time Speaker & Teacher.IRAN Reactconf,
Hastnama Creative Salutations, Finaux Cloud Limited
@iammilaad
TopicsToday’s Topics
D i f f e r e n t B e t w e e n C S R & S S R
- Let’s know Server-Side Rendering and Client-Side Rendering
@IAMMILAAD
A D e e p D i v e i n t o N e x t J S
R o u t i n g
- ways of routing in nextJS, Dynamic Routing, Nested Routing, Routing between pages and then tipis
and tricks
S t y l i n g
- ways of styling in nextJS. CSS. LESS. SCSS. CSS in JS, Styled Components.
TopicsToday’s Topics
F e t c h i n g D a t a & e r r o r h a n d l i n g s
- get data from APIs, getInitialProps and getServerSideProps, how to handle server errors in APIs
@IAMMILAAD
A D e e p D i v e i n t o N e x t J S
S i m p l e A u t h e n t i c a t i o n
- Authentication with cookies and use interceptors
C o n f i g a n d D e p l o y m e n t
- tips & tricks/ nextjs.config.js & .babelrc file config and development on server
SRR and CSRSSR and CSR
Server-Side Rendering / Client-Side Rendering
CSRClient Side Rendering
a p p l i c a t i o n s f u l l y g e n e r a t e d b y J a v a s c r i p t i n
t h e b r o w s e r s
@IAMMILAAD
w e n e e d t o k n o w a b o u t
o u r J S b u n d l e w i l l f e t c h a f t e r o n e o r t w o
s e c o n d s
a f t e r J S l o a d e d , v i r t u a l D O M m o v e d t o t h e
b r o w s e r D O M f o r t h e p a g e t o b e v i e w a b l e
Client
Rendered
Application
Client
Rendered
Application
A typical response sent by the server when requesting a
React site will look something like this:
index.html contains all the CSS and JS
CSR issuesCSR issues
J S c o d e s c a n n o t r u n o n o l d d e v i c e s o r
b r o w s e r s
@IAMMILAAD
  t w o m a j o r i s s u e s i n C S R
s e a r c h e n g i n e s a n d s o c i a l n e t w o r k s c a n n o t
c r a w l y o u r w e b s i t e
Server
Rendered
Application
Server
Rendered
Application
rendering a client-side single page application (SPA) on the
server and then sending a fully rendered page to the client.
NextJS is a simple powerful framework to make react
universal applications.
NextJSNextJS
Next.js gives you the best developer experience with all the features you need for production:
hybrid static & server rendering, TypeScript support, smart bundling, route pre-fetching, and more.
No config needed.
RoutingRouting
1 . f i l e - s y s t e m b a s e d r o u t i n g
@IAMMILAAD
N e x t J S R o u t e r
2 . c u s t o m r o u t i n g
File-system
Based
Routing
File-system
Based
Routing
and also supports nested routing with file-system based.
When a file is added to the pages directory it's
automatically available as a route.
Custom
Server
Routing
Custom
Server
Routing
in this way, you should disable file-system routing
IT’S CALLED “Custom Server”
Dynamic
Routing
Dynamic
Routing
• ebay.com/profile/dasboard
• ebay.com/profile/messages/conversation/PUdkuy2Sdo5EXqO
• ebay.com/profile/messages/conversation/PUdkuy2Sdo5EXqO/55
handle dynamic urls like ebay.com/products/
nike-react
Dynamic
Routing
Working with
Dynamic Routing
inside getInitialProps or
getServerSideProps
h o w t o g e t a n d m a n i p u l a t e d y n a m i c s t r i n g f r o m u r l
@iammilaad
inside component and using
withRouter
Routing
Between
Dynamic
Pages
Routing
Between
Dynamic
Pages
• href -> physical component address in pages
• as -> the url that will be shown in the browser
navigate to another page without loosing app
state
TipsRouting Tips
1 . m a k e y o u r o t h e r c o m p o n e n t s o u t s i d e o f
p a g e s f o l d e r
@IAMMILAAD
t i p s a n d t r i c k s i n r o u t i n g
2 . d i v i d e y o u r c o m p o n e n t s f o l d e r i n t h r e e
d i f f e r e n t t y p e s
•index.js
•style.js
•constants.js
StylingStyling
CSS / LESS / SASS / CSS IN JS / STYLED COMPONENTS
Fetching DataFetching Data
get data from APIs and using pre-rendered mode.
Fetch in
Server
pass to
Client
Fetch in
Server
pass to
Client
then we can access regionData, categoryData and query as a props in our
component and we can pass props to our children components.
for using pre-rendered mode you ned to call
getServerSideProps or getInitialProps
Fetch in Server
Pass to Client
Fetch in Server
Pass to Client
Errors Between
Client nd Server
Errors Between
Client and Server
i n t h i s e x a m p l e , i u s e d a p i s a u c e l i b r a r y t o
f e t c h d a t a a n d   u s i n g a d d R e s p o n s eT r a n s f o r m
f u n c t i o n , I n o r d e r   t o h a n d l e s u c c e s s o r f a i l u r e
A P I s w h e n r e s p o n s e s t a t u s
Error ComponentError Component
p a s s e s s t a t u s A P I c o d e s a s a p r o p s t o p a r e n t
c o m p o n e n t s s h o w c o n d i t i o n a l l y c o m p o n e n t s .
in app.js
M a k e s u r e t o k e e p t h a t i n m i n d , w e s h o u l d
c a l l g e t S e r v e r S i d e P r o p s o r g e t I n i t i a l P r o p s
f u n c t i o n s i n s i d e r o o t c o m p o n e n t .
AuthenticationAuthentication
s i m p l e A u t h e n t i c a t i o n i n N e x t J S a n d o n e a c h
r e q u e s t , t h e u s e r ’ s t o k e n w o u l d b e s e n t w i t h
t h e m i f i t e x i s t s i n t h e u s e r ’ s c o o k i e .
difference between
getInitialProps &
getServerSideProps
difference between
getInitialProps &
getServerSideProps
g e t I n i t i a l P r o p s
- run in server and browser and you may have to write codes specifically for the browser and server.
g e t S e r v e r S i d e P r o p s
- getServerProps just work on the server and do not run in the browser.
ImportantImportant Tip
getInitialProps and getServerSideProps just work in root
components like page/event.js and you should pass results
as a props to children components.
@IAMMILAAD
Deployment
and
Production
Ready
Deployment
and
Production
Ready
- Analyze the bundle pack
- Uglify and Minify JS Bundles
- minify CSS Bundles
- Remove Source Maps and comments
- set environment variables
- manage and keep your application online on the server
t i p s f o r o p t i m i z e b u i l d
a n d d e p l o y m e n t
BundleAnalyzerBundleAnalyzer package
@iammilaad
T r e e m a p s i z e s
Uglify
Minify
SourceMaps
Uglify
Minify
SourceMaps
Creating an optimized production build.
.ENV.ENV
- next-runtime-dotenv package
- dotenv pacakge
@IAMMILAAD
@IAMMILAAD
DeploymentDeployment
ecosystem.conf ig.js
P M 2 P a c k a g e
Thank
You.
Milad
Heydari
Thank
You.
Milad
Heydari
you can reach me anytime at
miladheydari.work@gmail.com.
T h e E n d
@iammilaad

More Related Content

What's hot (20)

PDF
ReactDC Intro to NextJS 9
Allison Kunz
 
PPTX
Nextjs13.pptx
DivyanshGupta922023
 
PDF
Frontrunners react
Allison Kunz
 
PDF
Universal React apps in Next.js
🐕 Łukasz Ostrowski
 
PDF
NEXT.JS
Binumon Joseph
 
PPTX
Server side rendering review
Vladyslav Morzhanov
 
PDF
React Server Side Rendering with Next.js
Jamie Barton 👨🏻‍💻
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
PPTX
Next.js vs React | what to choose for frontend development_
ForceBolt
 
PPTX
React workshop
Imran Sayed
 
PPTX
Node.js Express
Eyal Vardi
 
PDF
NodeJS for Beginner
Apaichon Punopas
 
PPTX
Express js
Manav Prasad
 
PDF
React js
Rajesh Kolla
 
PDF
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
PPTX
Reactjs
Neha Sharma
 
PDF
Next.js Introduction
Saray Chak
 
PPTX
React Native
ASIMYILDIZ
 
PPTX
Node js
Fatih Şimşek
 
PPTX
ReactJs
Sahana Banerjee
 
ReactDC Intro to NextJS 9
Allison Kunz
 
Nextjs13.pptx
DivyanshGupta922023
 
Frontrunners react
Allison Kunz
 
Universal React apps in Next.js
🐕 Łukasz Ostrowski
 
Server side rendering review
Vladyslav Morzhanov
 
React Server Side Rendering with Next.js
Jamie Barton 👨🏻‍💻
 
Introduction Node.js
Erik van Appeldoorn
 
Next.js vs React | what to choose for frontend development_
ForceBolt
 
React workshop
Imran Sayed
 
Node.js Express
Eyal Vardi
 
NodeJS for Beginner
Apaichon Punopas
 
Express js
Manav Prasad
 
React js
Rajesh Kolla
 
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
Reactjs
Neha Sharma
 
Next.js Introduction
Saray Chak
 
React Native
ASIMYILDIZ
 

Similar to NextJS - Online Summit for Frontend Developers September 2020 (20)

PDF
Angular server side rendering with NodeJS - In Pursuit Of Speed
Ilia Idakiev
 
PDF
Going web native
Marcus Hellberg
 
PPTX
What it Means to be a Next-Generation Managed Service Provider
Datadog
 
PPT
Informix SQL & NoSQL: Putting it all together
Keshav Murthy
 
PDF
OOScss Architecture For Rails Apps
Netguru
 
PDF
Introduction to Ruby on Rails
Diki Andeas
 
PDF
Meteor - not just for rockstars
Stephan Hochhaus
 
PDF
A Journey with React
FITC
 
PDF
Building a Single Page Application using Ember.js ... for fun and profit
Ben Limmer
 
PPTX
Innovations and trends in Cloud. Connectfest Porto 2019
javier ramirez
 
PPT
Building Web Hack Interfaces
Christian Heilmann
 
PPTX
Data Lake na área da saúde- AWS
Amazon Web Services LATAM
 
ODP
* DJANGO - The Python Framework - Low Kian Seong, Developer
Linuxmalaysia Malaysia
 
PDF
Developing for LinkedIn's Application Platform
Taylor Singletary
 
PPT
Open Source Web Technologies
Aastha Sethi
 
PDF
Java in 21st century: Are you thinking far enough ahead ?
Steve Wallin
 
PDF
機械学習エンジニアを見せたAWSの再:発明とは? 〜re:Invent 2018 参加レポート〜
cyberagent
 
KEY
Intro To Django
Udi Bauman
 
KEY
Modular Web Applications With Netzke
netzke
 
PDF
Let's Work Together
Aquent
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Ilia Idakiev
 
Going web native
Marcus Hellberg
 
What it Means to be a Next-Generation Managed Service Provider
Datadog
 
Informix SQL & NoSQL: Putting it all together
Keshav Murthy
 
OOScss Architecture For Rails Apps
Netguru
 
Introduction to Ruby on Rails
Diki Andeas
 
Meteor - not just for rockstars
Stephan Hochhaus
 
A Journey with React
FITC
 
Building a Single Page Application using Ember.js ... for fun and profit
Ben Limmer
 
Innovations and trends in Cloud. Connectfest Porto 2019
javier ramirez
 
Building Web Hack Interfaces
Christian Heilmann
 
Data Lake na área da saúde- AWS
Amazon Web Services LATAM
 
* DJANGO - The Python Framework - Low Kian Seong, Developer
Linuxmalaysia Malaysia
 
Developing for LinkedIn's Application Platform
Taylor Singletary
 
Open Source Web Technologies
Aastha Sethi
 
Java in 21st century: Are you thinking far enough ahead ?
Steve Wallin
 
機械学習エンジニアを見せたAWSの再:発明とは? 〜re:Invent 2018 参加レポート〜
cyberagent
 
Intro To Django
Udi Bauman
 
Modular Web Applications With Netzke
netzke
 
Let's Work Together
Aquent
 
Ad

Recently uploaded (20)

PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Ad

NextJS - Online Summit for Frontend Developers September 2020