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
data_between_rails_and_javascript.pdf
Search
Keiko Kaneko
PRO
September 12, 2019
1
1.7k
data_between_rails_and_javascript.pdf
Keiko Kaneko
PRO
September 12, 2019
Tweet
Share
More Decks by Keiko Kaneko
See All by Keiko Kaneko
観る将、指す将、TyP 〜時を越えた将棋指しの魅力〜
neko314
PRO
0
8
Introduce-my-gem-factory_strategist
neko314
PRO
1
5.3k
20201212_rails_girls_gathering_japan
neko314
PRO
0
1.1k
about-nerimarb
neko314
PRO
0
260
Why I chose to be a programmer
neko314
PRO
0
180
RailsGirlsTokyo9th--neko
neko314
PRO
0
55
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
22
3.9k
A Modern Web Designer's Workflow
chriscoyier
690
190k
Design by the Numbers
sachag
277
19k
Mobile First: as difficult as doing things right
swwweet
220
8.8k
Done Done
chrislema
180
16k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Code Reviewing Like a Champion
maltzj
518
39k
Intergalactic Javascript Robots from Outer Space
tanoku
268
26k
How to Ace a Technical Interview
jacobian
275
23k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
157
15k
Atom: Resistance is Futile
akmur
261
25k
Transcript
Rails ͱ JSͷσʔλڮ͠ ʹ͍ͭͯߟ͑ͯΈͨ 2019/09/12 ۜ࠲Rails#13 ۚࢠܚࢠ @neko314
ɾ@neko314 / @neko314_ ɾ࣌ʑNerima.rbͬͯ·͢ ɾAsakura.rb ͔ΒࢀΓ·ͨ͠ ࣗݾհ
ΞΫτΠϯσΟͰಇ͍ͯ·͢
چλΠτϧ ʮJS Lv.1͚ͩͲRailsΞϓϦ্Ͱͷ Vue.jsͷΑ͍ॻ͖ํΛௐͯΈͨʯ λΠτϧٗʢະʣͰͨ͠!
❌RailsͱVue.jsͷ ⭕RailsͱJavaScriptͷ ్தͰม͑ͨ มΘͬͯ͠·͍·ͨ͠
Rails ˱ JavaScript σʔλͷड͚͠ʹ͍ͭͯ ͢͜ͱ
ʮͳͥ͜͏࣮͢Δͷ͔ʯ ͱ͍͏அཧ༝Λ໌֬ʹ͢Δ͜ͱ ํ๏ ΰʔϧ
ۀͰVue.jsΛ͍ҰཡΛ࡞ͬͨ ʮ͜͏ΕͰ͖ΔʯͰ࣮ͨ͠ ͜ͷ··Ͱ͍Δͷ͍ͩͬͨ ͳͥ͜ͷΛʁ
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔ ࣮ํ๏
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔ ࣮ํ๏ ۀͰॻ͍ͨ ͷͪ͜Β
API͏ͷͬͯΉ͕ͩଟ͍ͷͰʁ ௨৴༨ܭʹൃੜ͢Δ͠ HTMLͱJSONͱJSͬͯ༻ҙ͢Δͷ ໘ͳײ͡ͳΜ͔ͦ͏ ๊͍ͨٙ
DOMͷํͰͬͨ΄͏͕ Α͔ͬͨΓ͢ΔͷͰɾɾɾʁ ๊͍ͨٙ
Ͱɺܭଌͯ͠ΈΑ͏
ɾRails → JS - ࢀর ɾJS →Rails - ࡞ɾߋ৽ɾআ ݕূ༰
ɾRails → JS - ࢀর ɾJS →Rails - ࡞ɾߋ৽ɾআ ݕূ༰
ٙʹج͖ͮ ࠓճͪ͜Β
ɾύϑΥʔϚϯε ɾσʔλͷ߹ੑ ɾ࣮ϝϯς͢͠͞ ݕূج४
ɾύϑΥʔϚϯε ɾσʔλͷ߹ੑ ɾ࣮ϝϯς͢͠͞ ݕূج४ ಉ͘͡ࠓճ ͪ͜Β
αϯϓϧΞϓϦΛ࡞ͬͯ ҧ͍Λൺֱ ݕূํ๏
࡞ͬͨͷ ɾϢʔβʔ1,000݅ ɾJSଆͰϖʔδ ωʔγϣϯ
ڥ ɾRuby 2.6.4 ɾRails 6.0.0 ɾWebpacker 4.0.7 ɾVue.js 2.6.10 ɾGoogle
Chrome ※ProductionڥͰىಈͨ͠localhost Ͱॾʑܭଌ͠·ͨ͠
NetworkͷΛൺֱ ॳճʴ 9ճϦϩʔυͷ10ճ ܭଌ
AuditsύωϧͰ First Meaningful Paintൺֱ ܭଌ
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔ ࣮ํ๏
APIͷ࣮ Controller HTML JS
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔˠgon ࣮ํ๏
gonʹ͍ͭͯ
None
DOMʹΛͨͤΔ࣮ Controller HTML JS
݁Ռൃද
Request ϦΫΤετճ ʢճʣ ʢճʣ DOM API
Resources Ϧιʔεͷ༰ྔ ʢKBʣ DOM API
Transferred సૹྔ ʢKBʣ ʢճʣ DOM API
Finish ϖʔδ͕දࣔ͞ΕΔ·Ͱͷ࣌ؒ ʢKBʣ ʢճʣ DOM API
DOMContentLoaded HTMLͷಡΈࠐ·ΕΔ·Ͱͷ࣌ؒ ʢmsʣ ʢճʣ DOM API
Load ϖʔδͷಡΈࠐΈ͕ऴΘΔ·Ͱͷ࣌ؒ ʢmsʣ ʢճʣ DOM API
First Meaningful Paint ҙຯ͋Δ༰͕දࣔ͞ΕΔ࣌ؒ DOM API ʢmsʣ
·ͱΊʢ̍ʗ̎ʣ DOM API Request ⭕ Resources ⭕ Transferred ⭕
·ͱΊʢ̎ʗ̎ʣ DOM API Finish ⭕ DOMContent Loaded ⭕ Load ⭕
First Meaningful Paint ⭕
·ͱΊʢ̎ʗ̎ʣ DOM API Finish DOMContent Loaded ⭕ Load ⭕ First
Meaningful Paint දࣔ࢝͠ΊAPI͕ૣ͍
·ͱΊʢ̎ʗ̎ʣ DOM API Finish DOMContent Loaded Load First Meaningful Paint
⭕ AuditsͷఆAPI͕ૣ͍
·ͱΊʢ̎ʗ̎ʣ DOM API Finish ⭕ DOMContent Loaded Load First Meaningful
Paint දࣔऴΘΓDOM͕ૣ͍
APIͷԿ͕͍͔ API෦ͷऴྃͪͷ͕࣌ؒ͋Δ HTML: 15ms JSON: 352ms
ͰDOM users(index.html)ʹ ͕͔͔͍࣌ؒͬͯΔ
HTMLͷେ͖͞ͱॲཧ࣌ؒ DOM API αΠζ 335KB 818B ࣌ؒ 230ms 15ms DOMʹΛͨͤΔͱHTMLͷαΠ
ζ͕େ͖͘ͳΓॲཧʹ͕͔͔࣌ؒΔ
ɾHTMLͷදࣔૣ͍ ɾHTMLͷදࣔͱσʔλͷड͚ ͠දࣔʹ͕࣌ؒࠩ͋Δ APIͰ࣮͢Δͱ
ɾHTMLͷදࣔ࢝͠Ί͍ ɾશମ͕දࣔ͠ऴΘΔͷૣ͍ ɾܭଌπʔϧͷධՁ͕͍͍ͷ͜ ͪΒ DOMͷ߹
API͏ͷͬͯΉ͕ͩଟ͍ͷͰʁ ௨৴༨ܭʹൃੜ͢Δ͠ HTMLͱJSONͱJSͬͯ༻ҙ͢Δͷ ໘ͳײ͡ͳΜ͔ͦ͏ ๊͍ͨٙ
๊͍ͨٙͷ͑ Α͘Θ͔Βͳ͍ʂ
ʮͳͥ͜͏࣮͢Δͷ͔ʯ ͱ͍͏அཧ༝Λ໌֬ʹ͢Δ͜ͱ ΰʔϧୡͨ͠ʁ
ΰʔϧୡͨ͠ʁ ҧ͍ΛΔ͜ͱ͕Ͱ͖ͨ ·͔ͩΒͳ͍ ͬͱΓ͍ͨ
ɾ͜ͷޡࠩϢʔβʔͷମײʹӨ ڹ͕͋Δ͔ɺ͋ΔͳΒͲͷఔʁ ͬͱ͔֬Ί͍ͨٙ
ɾ͕݅มΘΔͱͲ͏ͳΔ͔ʁ ɾͬͱ៛ີʹܭଌ͢Δͱʁ ͬͱ͔֬Ί͍ͨٙ
ɾܭଌָ͔ͬͨ͠ ɾϑϩϯτʗαʔόʔͷશମΛΈ ͯ࠷దղͳ࣮Λߟ͑ΒΑ͏ ʹͳΓ͍ͨ ײ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠☺