Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Frontend Performance Tuning TIPS *n

Ayumu Sato
January 25, 2014

Web Frontend Performance Tuning TIPS *n

Frontrend in Fukuoka http://frontendfrogs.org/frontrend/ で使用したスライドです。本編45分。

Ayumu Sato

January 25, 2014
Tweet

More Decks by Ayumu Sato

Other Decks in Programming

Transcript

  1. & ' #BDLFOE %# 8FC"QQ ( ) 'SPOUFOE #SPXTFS *

    )5.- MJOLISFGGPPDTTʜ TDSJQUTSDCBSKTʜ JNHTSDRVYKQHʜ
  2. & ' #BDLFOE %# 8FC"QQ ( ) 'SPOUFOE #SPXTFS *

    )5.- ◅◅◅◅◅ (&5GPPDTT (&5CBSKT (&5RVYKQH ◅◅◅◅◅ ◅◅◅◅◅
  3. & ' #BDLFOE %# 8FC"QQ ( ) 'SPOUFOE #SPXTFS *

    )5.- ▻▻▻▻▻ ▻▻▻▻▻ ▻▻▻▻▻ * $44 * +4 , +1(
  4. & ' #BDLFOE %# 8FC"QQ ( ) 'SPOUFOE #SPXTFS *

    )5.- ▻▻▻▻▻ ▻▻▻▻▻ ▻▻▻▻▻ * $44 * +4 , +1( ϑϩϯτΤϯυͷ੹೚
  5. %BUB63* $444QSJUFT , , , , ,, ,,, , ,

    , , , , , , , , , , , , , , * $44 , , , , , , div { width: 100px; height: 50px; border-radius: 3px; … .. .
  6. ⬅ όΠφϦσʔλΛ จࣈྻͱͯ͠ຒΊࠐΉ * $44 background-image: url(“data:image/ jpeg;base64,/9j4AAQSkZJRgABAQAA AQABAAD2wBDAAMCAggICAgICAgI CAgICAgICAgICAgICAgICAgICAgICA

    gICAgICAgICAgICAoICAgICQoKCAg MDAoIDAgICQj2wBDAQMEBAYFBgo GBgoNDAwNDQ0NDQwMDQ0MDA0 MDQ0MDAwMDQwMDAwMDAwMDA wMDAwMDAwMDAwMDAwMDAwMD AwMDAzwAARCADIAMgDAREAAhEB AxEB8QAHQAAAgEFAQEAAAAAAAA AAAAAAQIAAwQFBgcICfEAEUQAAIB AgMEBwMJBgUDBQAAAAECAAMRB BIhBQYxQQcIE1FhcZEiMoEjQlJicqGx wfAUM4KissIVNFPR8WOSoyRDc4Ph8 QAGwEAAgIDAQAAAAAAAAAAAAAA AAECAwQFBgf/xAAvEQACAgEEAg…
  7. var $list = $(‘#list’); // ͪΐͬͱۃ୺Ͱ͕͢… $list.append(‘<li>Item1</li>’ + ’<li>Item2</li>’ +

    ‘<li>Item3</li>’ + ‘<li>Item4</li>’ + ‘<li>Item5</li>’); ! <ul id=“list”></ul>
  8. // ͨ͘͞Μͷ TD ΁ɺݸผʹΠϕϯτΛషΔ $(‘table td’).on(‘click’, function() { // do

    something }); ! // ͻͱͭͷ table ʹΠϕϯτΛషΔ $(‘table’).on(‘click’, ‘td’, function() { // do something });
  9. // ͨ͘͞Μͷ TD ΁ɺݸผʹΠϕϯτΛషΔ $(‘table td’).on(‘click’, function() { // do

    something }); ! ! <table> <tr> <td>ηϧ1</td> <td>ηϧ2</td> <td>ηϧ3</td> </tr> </table> #    2
  10. // ͻͱͭͷ TABLE ʹΠϕϯτΛషΔ $(‘table’).on(‘click’, ‘td’, function() { // do

    something }); ! ! <table> <tr> <td>ηϧ1</td> <td>ηϧ2</td> <td>ηϧ3</td> <tr> </table> #     ! 2
  11. /* Underscore.JS */ ! // scroll ʹ߹ΘͤͯҐஔΛߋ৽͢ΔԿ͔ var throttled =

    _.throttle(updatePos, 100); $(window).scroll(throttled); ! // resize ʹ൓Ԡͯ͠ϨΠΞ΢τ͠௚͢Կ͔ var lazyLayout = _.debounce(calcLayout,300); $(window).resize(lazyLayout);
  12. function updateSprites(dt) { for (var sprite in sprites) { sprite.position.x

    += 0.5 * dt; // 20 more lines of arithmetic computation. } }
  13. function updateSprites(dt) { for (var sprite in sprites) { updateSprite(sprite,

    dt); } } ! function updateSprite(sprite, dt) { sprite.position.x += 0.5 * dt; // 20 more lines of arithmetic computation. } ϧʔϓ಺ͷॲཧΛผؔ਺ʹ෼཭͢Δ͜ͱͰ ࠷దԽ͕ద༻͞ΕΔΑ͏ʹͳͬͨ Β͍͠
  14. var timer; ! $(document).on(‘ajaxSend’, function(){ timer = setTimeout(function() { $(‘#loading’).show();

    }, 300); }); ! $(document).on(‘ajaxComplete’, function(){ clearTimeout(timer); $(‘#loading').hide(); });
  15. // λον։࢝࣌ʹɺis-activeΫϥεΛ෇༩͢Δ $(document).on('touchstart','a',function() { $(this).addClass('is-active'); }); ! // λονऴྃ࣌ʹɺis-activeΫϥεΛղআ͢Δ $(document).on('touchend',

    'a', function() { $(this).removeClass('is-active'); }); ! // ݫີʹ͸ɺUIͷछྨʹΑͬͯɺΫϥεண୤ͷͱ͖ʹ // σΟϨΠΛ͔͚ͯνϡʔχϯά͠ͳ͍ͱࣗવʹͳΒͳ͍