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
MPA化するSPAとSPA化するMPA
Search
Yosuke Furukawa
PRO
September 21, 2022
Programming
15
12k
MPA化するSPAとSPA化するMPA
2022/9/21 Techfeed カンファレンスで発表した MPA化するSPAとSPA化するMPA の話です。
Yosuke Furukawa
PRO
September 21, 2022
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
1
3.2k
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
170
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
350
Module Harmony について
yosuke_furukawa
PRO
3
1.6k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
720
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.4k
Other Decks in Programming
See All in Programming
CSC305 Lecture 25
javiergs
PRO
0
130
testcontainers のススメ
sgash708
1
120
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
660
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Zoneless Testing
rainerhahnekamp
0
120
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
450
Haze - Real time background blurring
chrisbanes
1
510
ドメインイベント増えすぎ問題
h0r15h0
1
120
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
Featured
See All Featured
It's Worth the Effort
3n
183
28k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Designing Experiences People Love
moore
138
23k
GitHub's CSS Performance
jonrohan
1030
460k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Bash Introduction
62gerente
608
210k
Writing Fast Ruby
sferik
628
61k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Building Adaptive Systems
keathley
38
2.3k
Transcript
MPAԽ͢ΔSPAͱ SPAԽ͢ΔMPA 2022/09/21 @ Techfeed
Twitter: @yosuke_furukawa Github: yosuke-furukawa
MPAԽ͢ΔSPA • ݩʑSPAը໘ભҠʢτϥϯδγϣϯʣΛΞϓ Ϧέʔγϣϯʹ߹Θͤͯ࠷దԽ͢ΔࣄΛతͱ ͍ͯ͠Δɻ • มߋ͕ൃੜͨ͠෦͚ͩΛϨϯμϦϯά͢Δ͜ ͱͰߴԽ͢ΔςΫχοΫ͕ͩͬͨɺͦΕΛ͢ ͯͷϖʔδͰߦ͏͜ͱͰશମͷUXΛ্͛Δɻ
MPAԽ͢ΔSPA 4FSWFS GET / HTML GET ./bundle.js JS 3FOEFSJOH ͜ͷ࣌Ͱදࣔ͞Ε͓ͯΓɺૢ࡞Մೳ
SPAͷɺݟ͑ΔΑ͏ʹͳΔ·ͰʢLCP, FMPʣ͕͍͜ͱ 4FSWFS GET / HTML GET ./bundle.js JS 3FOEFSJOH
͜͜ͷ࣌Ͱ·ͩίϯςϯπ͕ ݟ͑ͳ͍ ͜͜ͰΑ͏͘ݟ͑Δɻ ͦͷΘΓɺ͔͜͜ΒઌͷભҠ ΫϥΠΞϯτͰࠩϨϯμϦϯά ͢ΔͷͰૣ͘ײ͡Δ
Α͠ɺ͡Ό͋SSR/SSG/ISR ͩʂʂʂ • SSR/SSG/ISR શͯ࠷ॳͷHTMLΛฦ࣌͢Ͱ༰ؚΊ ͯฦ͢ͱ͍͏Ξϓϩʔν • SSRϦΫΤετ࣌ʹ࡞ΔͷɺSSGࣄલʹ࡞Δͷɺ ISRࣄલʹ࡞͓͍ͬͯͯޙ͔Βߋ৽͢ΔͷʢΩϟο γϡ͖SSRͱ΄΅ಉ༷ʣ
• ཁ HTML ΛԿ͔͠ΒͷλΠϛϯάͰ࡞͓͍ͬͯͯɺͦ ΕΛฦ͢
MPAٕज़ΛͬͯSPAΛ࡞Δ ʢMPAԽ͢ΔSPAʣ
MPAԽ͢ΔSPA 4FSWFS GET / HTML GET ./bundle.js JS SSR࣮ߦ HTML
ඳը JS load
͜ͷ࣌ͰେMPAͱSPAͷྑ ͍ͱ͜ΖͲΓΛ͍ͯ͠Δ • ͱͱMPAͷٕज़Ͱ͋ΔHTMLΛαʔόα ΠυͰϨϯμϦϯά͢Δͷͱɺϩʔυ͞Εͨ ޙSPAͷٕज़ͱͯ͠ϋΠϒϦουઓུΛऔΔײ ͡ • SPA͚ͩͬͨͲɺঃʑʹMPAʹۙدͬͯΔ
MPAԽ͢ΔSPA 4FSWFS GET / HTML GET ./bundle.js JS SSR࣮ߦ HTML
ඳը JS load ͜ͷ࣌Ͱίϯςϯπ͕ݟ͑Δ ͨͩ͠ɺ͕ͭ͋Δ
MPAԽ͢ΔSPA 4FSWFS GET / HTML GET ./bundle.js JS SSR࣮ߦ HTML
ඳը JS load 443࣮ߦ࣌ͷ࣌ؒ )5.-ඳը͔Β+4MPBE·Ͱͷ࣌ؒ
1 ʹ͍ͭͯ • SSR࣮ߦ࣌ͷ࣌ؒ: ຖճϦΫΤετͯ͠Δ࠷தͷΦϯβϑϥΠͰ࡞ Δͷେ͖͍(ΠϕϯτϧʔϓࢭΊͪΌ͏ɺCPUίετߴ ͍ɺ݁Ռαʔό͔ΒHTMLฦΔ·Ͱͷίετֻ͔Δ)ɻ • ͔ͱ͍ͬͯɺSSGͩͱࣄલʹશ෦࡞Βͳ͍ͱ͍͚ͳ͍ •
͔ͱ͍ͬͯɺISRͩͱ݁ہΩϟογϡͳͷͰɺrevalidate ظؒΛ ͘͢ΕSSRͱಉͩ͡͠ɺ͘͢Εࠓ࠷৽ө͞ΕΔ·Ͱͷ ظ͕ؒԆͼΔʢΩϟογϡϥΠϑαΠΫϧͷʹΛม͑Δ͜ ͱͰ͖Δ͕ɺͦΕͩͬͨΒ CDN + SSR Ͱಉ͜͡ͱͰ͖Δʣ
1 ʹ͍ͭͯ • ཁࠓͷॴಛʹࠜຊతͳղܾࡦͳ͘ɺΩϟο γϡΛ࣋ͭ or ΤοδαΠυʹ࣋ͬͯߦͬͪΌͬ ͯͳΜͱ͔͠Α͏ͱ͍ͯ͠Δϑγ͕͋Δɻ • React
18 ͱ Next 12 Ͱ Streaming SSR ͳͲ ͷํ๏͋Δɻ͜ΕʹΑΓɺग़དྷ্͕ͬͨͱ͜ Ζ͔Βͪΐͬͱͣͭฦͤྑ͍Μ͡ΌͶʁ࡞ઓ ͋Δɻ
Streaming SSR 4FSWFS GET / HTML MPBEJOH Streaming SSR HTML
ඳը։࢝ Fragment Fragment HTML ඳըऴྃ
2 ʹ͍ͭͯ • ཁݟ͑Δͷʹԡͤͳ͍ʂʂʂͱ͍͏ • ͜Ε͕ࠓͷॴϑϨʔϜϫʔΫք۾Ͱϗοτ τϐοΫ • LCPʢॏཁͳίϯςϯπ͕ݟ͑Δ·Ͱʣ͍ ͚Ͳɺ͔ͦ͜ΒTTI
(ૢ࡞Մೳ)ʹͳΔ͕࣌ؒ ͍ͱ͍͏ঢ়گ
2 ʹ͍ͭͯ • ͦͦ bundle.js ͷαΠζͰ͔͍͔ΒΖ͏ͥͬ ͍ͯ͏ͪΖΜ͋Δɻ • Next.js Ͱ
͋Δఔϖʔδ͝ͱϥΠϒϥϦͷα ΠζͲ͔͜ΒͰΘΕͯΔϥΠϒϥϦ͔Ͳ͏ ͔ͷใ͔Β࠷దԽͨ͠ code split Λͯ͘͠ΕΔ • ݱঢ়ͷ࠷దԽ͜͜ࢭ·Γɻ
2 ʹ͍ͭͯ • React ਞӦ: Selective Hydration ͩʂʂ (PPHMF*0ΑΓ
2 ʹ͍ͭͯ • ཁશ෦ͷίϯϙʔωϯτʹରͯ͠Ұؾʹ ΔΜ͡Όͳͯ͘ஈ֊Λܦͯগͣͭͣͭ͠Δ
ͪΐͬͱͬͨʂʂʂ
ͦͦͳΜͰͦΜͳ͔࣌ؒ ͔ΔΜεΧʁReact ͞Μ
ͦͦͷΓํ͔Βݟ͠ ·ͤΜʁ
ͳΜͰͦΜͳʹ͔͔࣌ؒΔͷʁ • ·ͣJS͕ॏ͍ɻ • JS ͷϩʔυΛͨ͠ޙɺΠϕϯτϋϯυϥαʔόͰ࡞ΒΕͨঢ় ଶΛίϯϙʔωϯτʹొ͢Δͷʹ͕͔͔࣌ؒΔ(Hydration)ɻ • Πϕϯτϋϯυϥͨͩͷ७ਮͳؔ͡Όͳ͍ɺ෭࡞༻͕ ͋ͬͨΓɺ֎ଆͷঢ়ଶʹΠϯλϥΫτ͢Δɻ
• αʔόαΠυͰੜͨ͠ঢ়ଶͷ෮ؼʹ͕͔͔͍࣌ؒͬͯΔɻ
ର߅അͦͷ1: Astro • Astro ͦͦ MPA Λجຊͱ͍ͯ͠Δɻ • جຊΞΠσΞ React
/ Vue / Preact ͳΜͰ ͬͯྑ͍ɻͦͷΘΓαʔόαΠυͰϨϯμ Ϧϯά͢ΔͷΛجຊͱ͢Δɻ • ΫϥΠΞϯταΠυͰͷJSσϑΥϧτͰ࡞ Βͳ͍ɻ
ର߅അͦͷ1: Astro • ͑ɺͦΕ͡ΌͲ͏ͬͯ෦తʹߋ৽͢ΔΜͰ͔͢ʁ • ෦తͳߋ৽͍ͨ͠ίϯϙʔωϯτʢΫϥΠΞϯτͷJS͕ඞཁͳͷ ͚ͩʣૂͬͯ Hydration͢Δ(͜ΕҰԠ Selective Hydration
ͱ͍͑Δ) • SPAΛجຊͱ͍ͯ͠ͳ͍ͷͰɺඞཁͳͷʹ͚ͩJSΛޮ͔ͤΔͱ͍͏ߟ ͑ํ • ͨͩ React / Vue / YourFavFrameworks ී௨ʹ͑Δ͠ɺ׳ΕͨUIϑ ϨʔϜϫʔΫͰ։ൃͰ͖Δɻͦͷ্ͰίϯςϯπʹಛԽͨ͠ϖʔδͳΒ ॳظද͍ࣔɻ
ର߅അͦͷ1: Astro • ͋ͱɺΤοδͰஔ͘͜ͱαϙʔτ͍ͯ͠Δ • ͳͷͰɺ SSR ͩͱͯ͠Τοδͷࢄ͞ΕͨϊʔυͰ ಈ͘ͷͰ CPU
ෛՙͱ͔ͦ͜·Ͱؾʹ͠ͳͯ͘ྑ͍ ʢͣʣ • ͜͜ YourFavoriteEdge ʢAmplify, Cloudflare, Vercelʣʹஔ͍ͯ͑ྑ͍ʢͱ͍͏ࣄʹͳ͍ͬͯΔʣ
Astro ͷղܾࡦ • SSR͍ => Edge ʹஔ͚͓͚ • JS ॏͯ͘
TTI ͍ => ͦͦJS৴͠ͳ ͖Ό͓͚ • ΠϕϯτొͰ͖ͳͯ͘ɺ෦ߋ৽Ͱ͖ͳ͍ => ૂͬͨͱ͜Ζʹ͚ͩJSಡΈࠐ·ͤΓΌ͓͚
ର߅അͦͷ2: Qwik • Qwik جຊతʹ MPA • ͦͦॳظදࣔͱTTI͕͖Όྑ͍ΜΖʁ • Hydration
ͳΜ͍ͯͦͦΒΜ͔ͬͨΜ... •
ର߅അͦͷ2: Qwik • ݴ͍͍ͨ͜ͱ͜͜ʹશ෦٧·ͬͯΔɻ
ର߅അͦͷ2: Qwik • جຊઓུ: ͦͦ MPA ʹ͍ͯ͠Δɻ͋ͱɺ Hydration ͠ͳ͍ɻ •
Hydration ͠ͳ͍Μ͔ͩΒɺ JS ࠷খݶͰ ͍͍ɻ
ର߅അͦͷ2: Qwik • Q: ͑ɺͦΕ͡ΌͲ͏ͬͯΠϕϯτऔΔΜͰ͔͢ʁ • A: DOM ʹͦͦΠϕϯτϋϯυϥ͚͓͚ͯ͑͑Μ ɻ
• Q: ঢ়ଶɾɾɾʁ • A: ͦΕDOMʹॻ͖Ό͑͑Ζɻ • Q: ͑ɺͲ͏͍͏͜ͱɾɾɾʁ
ର߅അͦͷ2: Qwik • ͜͏͍͏͜ͱ
ର߅അͦͷ2: Qwik • ͜͏͍͏͜ͱ 3FBDUͷίϯϙʔωϯτΛॻ͘ POJOQVUϋϯυϥΛ%0.ʹೖΕ͓ͯ͘ Πϕϯτ͕ى͖ͨΒͦͷλΠϛϯάͰ+4Λ μϯϩʔυͯ͠ɺଓ͚ΒΕΔΑ͏ʹ͢Δɻ
Qwik ͷղܾࡦ • SSR͍ => qwik ͷαΠτʹಛʹͳ͔͚ͬͨ Ͳɺ͜͜Edgeʹ͓͚(ͷͣ) • JS
ॏͯ͘ TTI ͍ => ඞཁʹͳΔ·ͰJS৴͠ ͳ͍ઓུ • ΠϕϯτొͰ͖ͳͯ͘ɺ෦ߋ৽Ͱ͖ͳ͍ =>ඞཁʹͳ͔ͬͯΒͦ͜ʹ͚ͩμϯϩʔυͤ͞Δ
Astro vs Qwik vs Next.js • Qwik ͷձ͕ࣾͬͯΔϕϯνϚʔΫͳͷͰएׯ Qwik دΓ
55* -$1 'JMFTJ[F RXJL T T LC BTUSP T T LC OFYUKT T T LC IUUQTHJUIVCDPN#VJMEFS*0GSBNFXPSLCFODINBSLT
SPAٕज़ΛͬͯMPAΛ࡞Δ ʢSPAԽ͢ΔMPAʣ
ͨͩͬͺΓͦΕͩͱεϜʔεͳτϥ ϯδγϣϯۤखͳͷͰɾɾɾɾʁ • Chrome ͕த৺ʹͳͬͯਐΊ͍ͯΔ Shared Element Transition ͱͷΈ߹ΘͤͰεϜʔζτϥϯδγϣϯ࣮ ݱͰ͖ΔͱͷσϞ͋Γɻ
https://twitter.com/charca/status/1570835238359830529
SPA ɾ MPA ͍·࣍ͷε ςʔδʹདྷ͍ͯΔ
ଓ͖σΟεΧογϣϯͰ