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
7
18k
RailsエンジニアのためのNext.js入門
Kazuhito Hokamura
October 22, 2021
Tweet
Share
More Decks by Kazuhito Hokamura
See All by Kazuhito Hokamura
TypeScriptとGraphQLで実現する 型安全なAPI実装 / TSKaigi 2024
hokaccha
5
3.7k
Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話
hokaccha
0
3.1k
GraphQLの負債と向き合うためにやっていること
hokaccha
2
1.2k
ユビーのアーキテクチャに対する取り組み
hokaccha
1
340
Cookpad Summer Internship 2021 Web Frontend
hokaccha
0
7k
巨大なモノリシック Rails アプリケーションの マイクロサービス化戦略 / 2019 microservices in cookpad
hokaccha
3
3.7k
巨大なRailsアプリケーションを「普通」にするための取り組み
hokaccha
1
870
Web Frontend Improvement in Cookpad
hokaccha
1
970
cookpad summer internship 2018 - Git
hokaccha
1
9.5k
Other Decks in Technology
See All in Technology
contenteditableと向き合う
kikuchikakeru
2
140
[RSJ24] Object Segmentation from Open-Vocabulary Manipulation Instructions Based on Optimal Transport Polygon Matching with Foundation Models
keio_smilab
PRO
0
120
ログラスが面白いと思う理由をマネージャーがエモく語ってみる / 20240829 vs LT
yoshikiiida
1
520
OCI コスト管理
ocise
1
110
PlaywrightによるE2Eテスト入門 / Introduction to E2E Testing with Playwright
rhumie
3
910
SHIFTの課題と目指したい組織像 / 20240827 Rinto Ikenoue
shift_evolve
0
140
Oracle Database Backup Service:サービス概要のご紹介
oracle4engineer
PRO
0
4k
Namespace, Now and Then
tagomoris
0
170
目標設定と習慣化で今よりも一歩生産性を上げる
sansantech
PRO
7
2.3k
AWS版GitHub?Amazon CodeCatalystの全体像をまとめてみた
oshanqq
1
3.2k
LLMに日本語テキストを学習させる意義
ksaito
13
3.4k
いまからでも遅くない! コンテナでWebアプリケーションを 動かしてみよう(1)Gitハンズオン
nomu
0
280
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
230
130k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
363
22k
Fontdeck: Realign not Redesign
paulrobertlloyd
80
5.1k
Clear Off the Table
cherdarchuk
90
320k
GitHub's CSS Performance
jonrohan
1029
450k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
A designer walks into a library…
pauljervisheath
201
24k
RailsConf 2023
tenderlove
26
790
GraphQLの誤解/rethinking-graphql
sonatard
65
9.7k
Art, The Web, and Tiny UX
lynnandtonic
294
20k
Documentation Writing (for coders)
carmenintech
65
4.3k
Raft: Consensus for Rubyists
vanstee
135
6.5k
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͕͖ͳΤϯδχΞͳΒ͖ʹͳΔͱࢥ͏ɺͨͿΜʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ