Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RailsエンジニアのためのNext.js入門
Search
Kazuhito Hokamura
October 22, 2021
Technology
21k
7
Share
RailsエンジニアのためのNext.js入門
Kazuhito Hokamura
October 22, 2021
More Decks by Kazuhito Hokamura
See All by Kazuhito Hokamura
TypeScriptとGraphQLで実現する 型安全なAPI実装 / TSKaigi 2024
hokaccha
5
5k
Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話
hokaccha
0
3.8k
GraphQLの負債と向き合うためにやっていること
hokaccha
2
1.6k
ユビーのアーキテクチャに対する取り組み
hokaccha
1
470
Cookpad Summer Internship 2021 Web Frontend
hokaccha
0
7.3k
巨大なモノリシック Rails アプリケーションの マイクロサービス化戦略 / 2019 microservices in cookpad
hokaccha
3
4.1k
巨大なRailsアプリケーションを「普通」にするための取り組み
hokaccha
1
1.1k
Web Frontend Improvement in Cookpad
hokaccha
1
1.1k
cookpad summer internship 2018 - Git
hokaccha
1
9.8k
Other Decks in Technology
See All in Technology
SaaSに宿る21g
kanyamaguc
2
180
Zephyr(RTOS)でARMとRISC-Vのコア間通信をしてみた
iotengineer22
0
110
AIエージェント時代に必要な オペレーションマネージャーのロールとは
kentarofujii
0
230
Bref でサービスを運用している話
sgash708
0
210
How to install a gem
indirect
0
2k
Databricks Appsで実現する社内向けAIアプリ開発の効率化
r_miura
0
160
「活動」は激変する。「ベース」は変わらない ~ 4つの軸で捉える_AI時代ソフトウェア開発マネジメント
sentokun
0
140
パワポ作るマンをMCP Apps化してみた
iwamot
PRO
0
250
Why we keep our community?
kawaguti
PRO
0
350
GitHub Copilot CLI で Azure Portal to Bicep
tsubakimoto_s
0
300
LLMに何を任せ、何を任せないか
cap120
11
6.7k
20260323_データ分析基盤でGeminiを使う話
1210yuichi0
0
210
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The Curse of the Amulet
leimatthew05
1
11k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
1.9k
Practical Orchestrator
shlominoach
191
11k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
WENDY [Excerpt]
tessaabrams
9
37k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
180
We Have a Design System, Now What?
morganepeng
55
8k
So, you think you're a good person
axbom
PRO
2
2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
170
Transcript
RailsΤϯδχΞͷͨΊͷ Next.jsೖ Kaigi on Rails 2021
Ubie Discovery Kazuhito Hokamura @hokaccha @hokaccha
ࠓͷ 1. Next.jsͱԿ͔ 2. Next.jsͷػೳɾಛ
Next.jsͱԿ͔
None
None
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.
Next.jsRailsΛஔ͖͑ΔΑ͏ͳͷʁ
🙅
None
None
ͳͥNext.jsΛ͏ͷ͔
RailsϑϩϯτΤϯυͷϖΠϯ • ಠࣗ࿏ઢͳٕज़ελοΫ • JavaScriptͱhaml/erb͕ࠞ͟Δ • JavaScriptͰඳը͢Δ෦ͷPre Rendering͕ࠔ
Next.jsͩͱ • σϑΝΫτελϯμʔυͳٕज़͔ͭߴ͍։ൃମݧͷڥͰ։ൃͰ͖Δ • JavaScriptʢTypeScriptʣ͚ͩͰϑϩϯτΤϯυ͕݁͢Δ • Pre Rendering͕؆୯ʹ࣮ݱͰ͖Δ
͔͠͠Next.js͚ͩͩͱ • DBͷૢ࡞ϨΠϠʔ͕ͳ͍ • Blitz.jsͷΑ͏ͳϑϨʔϜϫʔΫ͕͋Δ͚Ͳ·ͩະख़
RailsͳͲͱΈ߹Θͤͯ͏ͷ͕ݱঢ়ͩͱϕλʔ
ΞʔΩςΫνϟͷྫ
👩💻 Frontend API Database
👩💻
👩💻
👩💻
͜͜·Ͱͷ·ͱΊ • Next.jsϑϩϯτΤϯυΛओ؟ʹ͓͍ͨϑϨʔϜϫʔΫ • RailsΛͦͷ··ஔ͖͑ΔΑ͏ͳͷͰͳ͍ • όοΫΤϯυ͕ಘҙͳϑϨʔϜϫʔΫͱΈ߹Θͤͯ͏ͷ͕Α͍
Next.jsͷػೳ
ಛతͳػೳ • Zero con fi g • File-system Routing •
Performance Optimization • Pre Rendering
Zero Con fi g
1. ඞཁͳϞδϡʔϧΛΠϯετʔϧ 2. React ComponentΛ࡞Δ 3. next dev Λ࣮ߦ͢Δ Ҏ্ɻ
File-system Routing
GET / GET /posts GET /posts/:id
GET / GET /posts GET /posts/:id
pages/posts/[id].tsx
Performance Optimization
͜͜Ͱ͍͏ύϑΥʔϚϯε Core Web Vitalsతͳҙຯ
Next.jsͷύϑΥʔϚϯε࠷దԽ • σϑΥϧτͰ༷ʑͳϕετϓϥΫςΟεͷద༻ • Code splitting, Critical Rendering Path࠷దԽ, etc...
• next/imageʹΑΔCLS࠷దԽ • next/linkʹΑΔը໘ભҠͷύϑΥʔϚϯε࠷దԽ • Pre RenderingʹΑΔFCP/LCPͷ࠷దԽ
Pre Rendering
Client Side Rendering
Client Side Rendering • ॳظඳըͷύϑΥʔϚϯε͕Ͱͳ͍ • JavaScriptΛ࣮ߦ͠ͳ͍ΫϥΠΞϯτʹऑ͍ʢOGP, SEOʣ
ͦ͜ͰPre Rendering • αʔόʔͰHTMLΛ࡞ͬͯฦ͢ → Server Side Rendering • ͋Β͔͡ΊHTMLΛ࡞͓͍ͬͯͯฦ͢
→ Static Site Generation
࣮ɺӡ༻͕࠷γϯϓϧɻύϑΥʔϚϯεOGPΛؾʹ͠ͳ͍Ͱ͍͍έʔεͰબͿ ύϑΥʔϚϯε࠷ڧɻ੩తʹੜͰ͖ͯύϑΥʔϚϯεʹͩ͜ΘΓ͍ͨέʔεͰ͜Ε ੩తʹੜ͢Δͷແཧ͚ͩͲॳظඳըͷύϑΥʔϚϯεOGP୲อ͍ͨ͠߹ʹ࠷ऴతʹબͿɻ ͦ͏͍͏έʔεͦΕͳΓʹ͋Δ🥲 Client Side Rendering Static Site Generation
Server Side Rendering ※ Incremental Static Regeneration ͱ͍͏ͷ͋Δ͚Ͳ࣌ؒͷ߹ͰׂѪ
SSR, SSG, CSRซ༻Մೳ • ಈతʹσʔλ͕มΘΔϖʔδSSR • ࣄલʹσʔλ͕Θ͔ΔϔϧϓϖʔδSSG • ύϑΥʔϚϯεOGPΛؾ͠ͳ͍ཧը໘CSR
Server Side Rendering ϦΫΤετΛड͚ͨͱ͖ʹ getServerSideProps͕࣮ߦ ͞ΕΔͷͰpropsΛ࡞ͬͯ͢
Static Site Generation Ϗϧυ࣌ʹgetStaticPathsͱ getStaticProps͕ݺΕͯಈత ʹ੩తϑΝΠϧΛੜ͢Δ
·ͱΊ
·ͱΊ • Next.jsRailsΛஔ͖͑ΔͷͰͳ͘ڞଘ͍ͯ͘͠ͷ • Next.jsͷ։ൃମݧେมΑ͍ͷͰҰճͬͯΈͯ΄͍͠ • Rails͕͖ͳΤϯδχΞͳΒ͖ʹͳΔͱࢥ͏ɺͨͿΜʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ