data_between_rails_and_javascript.pdf
by
Keiko Kaneko
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Rails ͱ JSͷσʔλڮ͠ ʹ͍ͭͯߟ͑ͯΈͨ 2019/09/12 ۜ࠲Rails#13 ۚࢠܚࢠ @neko314
Slide 2
Slide 2 text
ɾ@neko314 / @neko314_ ɾ࣌ʑNerima.rbͬͯ·͢ ɾAsakura.rb ͔ΒࢀΓ·ͨ͠ ࣗݾհ
Slide 3
Slide 3 text
ΞΫτΠϯσΟͰಇ͍ͯ·͢
Slide 4
Slide 4 text
چλΠτϧ ʮJS Lv.1͚ͩͲRailsΞϓϦ্Ͱͷ Vue.jsͷΑ͍ॻ͖ํΛௐͯΈͨʯ λΠτϧٗʢະʣͰͨ͠!
Slide 5
Slide 5 text
❌RailsͱVue.jsͷ ⭕RailsͱJavaScriptͷ ్தͰม͑ͨ มΘͬͯ͠·͍·ͨ͠
Slide 6
Slide 6 text
Rails ˱ JavaScript σʔλͷड͚͠ʹ͍ͭͯ ͢͜ͱ
Slide 7
Slide 7 text
ʮͳͥ͜͏࣮͢Δͷ͔ʯ ͱ͍͏அཧ༝Λ໌֬ʹ͢Δ͜ͱ ํ๏ ΰʔϧ
Slide 8
Slide 8 text
ۀͰVue.jsΛ͍ҰཡΛ࡞ͬͨ ʮ͜͏ΕͰ͖ΔʯͰ࣮ͨ͠ ͜ͷ··Ͱ͍Δͷ͍ͩͬͨ ͳͥ͜ͷΛʁ
Slide 9
Slide 9 text
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔ ࣮ํ๏
Slide 10
Slide 10 text
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔ ࣮ํ๏ ۀͰॻ͍ͨ ͷͪ͜Β
Slide 11
Slide 11 text
API͏ͷͬͯΉ͕ͩଟ͍ͷͰʁ ௨৴༨ܭʹൃੜ͢Δ͠ HTMLͱJSONͱJSͬͯ༻ҙ͢Δͷ ໘ͳײ͡ͳΜ͔ͦ͏ ๊͍ͨٙ
Slide 12
Slide 12 text
DOMͷํͰͬͨ΄͏͕ Α͔ͬͨΓ͢ΔͷͰɾɾɾʁ ๊͍ͨٙ
Slide 13
Slide 13 text
Ͱɺܭଌͯ͠ΈΑ͏
Slide 14
Slide 14 text
ɾRails → JS - ࢀর ɾJS →Rails - ࡞ɾߋ৽ɾআ ݕূ༰
Slide 15
Slide 15 text
ɾRails → JS - ࢀর ɾJS →Rails - ࡞ɾߋ৽ɾআ ݕূ༰ ٙʹج͖ͮ ࠓճͪ͜Β
Slide 16
Slide 16 text
ɾύϑΥʔϚϯε ɾσʔλͷ߹ੑ ɾ࣮ϝϯς͢͠͞ ݕূج४
Slide 17
Slide 17 text
ɾύϑΥʔϚϯε ɾσʔλͷ߹ੑ ɾ࣮ϝϯς͢͠͞ ݕূج४ ಉ͘͡ࠓճ ͪ͜Β
Slide 18
Slide 18 text
αϯϓϧΞϓϦΛ࡞ͬͯ ҧ͍Λൺֱ ݕূํ๏
Slide 19
Slide 19 text
࡞ͬͨͷ ɾϢʔβʔ1,000݅ ɾJSଆͰϖʔδ ωʔγϣϯ
Slide 20
Slide 20 text
ڥ ɾRuby 2.6.4 ɾRails 6.0.0 ɾWebpacker 4.0.7 ɾVue.js 2.6.10 ɾGoogle Chrome ※ProductionڥͰىಈͨ͠localhost Ͱॾʑܭଌ͠·ͨ͠
Slide 21
Slide 21 text
NetworkͷΛൺֱ ॳճʴ 9ճϦϩʔυͷ10ճ ܭଌ
Slide 22
Slide 22 text
AuditsύωϧͰ First Meaningful Paintൺֱ ܭଌ
Slide 23
Slide 23 text
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔ ࣮ํ๏
Slide 24
Slide 24 text
APIͷ࣮ Controller HTML JS
Slide 25
Slide 25 text
ᶃAPIΛ༻ҙ͢Δ ᶄDOMʹσʔλΛͨͤΔˠgon ࣮ํ๏
Slide 26
Slide 26 text
gonʹ͍ͭͯ
Slide 27
Slide 27 text
No content
Slide 28
Slide 28 text
DOMʹΛͨͤΔ࣮ Controller HTML JS
Slide 29
Slide 29 text
݁Ռൃද
Slide 30
Slide 30 text
Request ϦΫΤετճ ʢճʣ ʢճʣ DOM API
Slide 31
Slide 31 text
Resources Ϧιʔεͷ༰ྔ ʢKBʣ DOM API
Slide 32
Slide 32 text
Transferred సૹྔ ʢKBʣ ʢճʣ DOM API
Slide 33
Slide 33 text
Finish ϖʔδ͕දࣔ͞ΕΔ·Ͱͷ࣌ؒ ʢKBʣ ʢճʣ DOM API
Slide 34
Slide 34 text
DOMContentLoaded HTMLͷಡΈࠐ·ΕΔ·Ͱͷ࣌ؒ ʢmsʣ ʢճʣ DOM API
Slide 35
Slide 35 text
Load ϖʔδͷಡΈࠐΈ͕ऴΘΔ·Ͱͷ࣌ؒ ʢmsʣ ʢճʣ DOM API
Slide 36
Slide 36 text
First Meaningful Paint ҙຯ͋Δ༰͕දࣔ͞ΕΔ࣌ؒ DOM API ʢmsʣ
Slide 37
Slide 37 text
·ͱΊʢ̍ʗ̎ʣ DOM API Request ⭕ Resources ⭕ Transferred ⭕
Slide 38
Slide 38 text
·ͱΊʢ̎ʗ̎ʣ DOM API Finish ⭕ DOMContent Loaded ⭕ Load ⭕ First Meaningful Paint ⭕
Slide 39
Slide 39 text
·ͱΊʢ̎ʗ̎ʣ DOM API Finish DOMContent Loaded ⭕ Load ⭕ First Meaningful Paint දࣔ࢝͠ΊAPI͕ૣ͍
Slide 40
Slide 40 text
·ͱΊʢ̎ʗ̎ʣ DOM API Finish DOMContent Loaded Load First Meaningful Paint ⭕ AuditsͷఆAPI͕ૣ͍
Slide 41
Slide 41 text
·ͱΊʢ̎ʗ̎ʣ DOM API Finish ⭕ DOMContent Loaded Load First Meaningful Paint දࣔऴΘΓDOM͕ૣ͍
Slide 42
Slide 42 text
APIͷԿ͕͍͔ API෦ͷऴྃͪͷ͕࣌ؒ͋Δ HTML: 15ms JSON: 352ms
Slide 43
Slide 43 text
ͰDOM users(index.html)ʹ ͕͔͔͍࣌ؒͬͯΔ
Slide 44
Slide 44 text
HTMLͷେ͖͞ͱॲཧ࣌ؒ DOM API αΠζ 335KB 818B ࣌ؒ 230ms 15ms DOMʹΛͨͤΔͱHTMLͷαΠ ζ͕େ͖͘ͳΓॲཧʹ͕͔͔࣌ؒΔ
Slide 45
Slide 45 text
ɾHTMLͷදࣔૣ͍ ɾHTMLͷදࣔͱσʔλͷड͚ ͠දࣔʹ͕࣌ؒࠩ͋Δ APIͰ࣮͢Δͱ
Slide 46
Slide 46 text
ɾHTMLͷදࣔ࢝͠Ί͍ ɾશମ͕දࣔ͠ऴΘΔͷૣ͍ ɾܭଌπʔϧͷධՁ͕͍͍ͷ͜ ͪΒ DOMͷ߹
Slide 47
Slide 47 text
API͏ͷͬͯΉ͕ͩଟ͍ͷͰʁ ௨৴༨ܭʹൃੜ͢Δ͠ HTMLͱJSONͱJSͬͯ༻ҙ͢Δͷ ໘ͳײ͡ͳΜ͔ͦ͏ ๊͍ͨٙ
Slide 48
Slide 48 text
๊͍ͨٙͷ͑ Α͘Θ͔Βͳ͍ʂ
Slide 49
Slide 49 text
ʮͳͥ͜͏࣮͢Δͷ͔ʯ ͱ͍͏அཧ༝Λ໌֬ʹ͢Δ͜ͱ ΰʔϧୡͨ͠ʁ
Slide 50
Slide 50 text
ΰʔϧୡͨ͠ʁ ҧ͍ΛΔ͜ͱ͕Ͱ͖ͨ ·͔ͩΒͳ͍ ͬͱΓ͍ͨ
Slide 51
Slide 51 text
ɾ͜ͷޡࠩϢʔβʔͷମײʹӨ ڹ͕͋Δ͔ɺ͋ΔͳΒͲͷఔʁ ͬͱ͔֬Ί͍ͨٙ
Slide 52
Slide 52 text
ɾ͕݅มΘΔͱͲ͏ͳΔ͔ʁ ɾͬͱ៛ີʹܭଌ͢Δͱʁ ͬͱ͔֬Ί͍ͨٙ
Slide 53
Slide 53 text
ɾܭଌָ͔ͬͨ͠ ɾϑϩϯτʗαʔόʔͷશମΛΈ ͯ࠷దղͳ࣮Λߟ͑ΒΑ͏ ʹͳΓ͍ͨ ײ
Slide 54
Slide 54 text
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠☺