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

Image optimization for mobile on CDN

r-plus
December 22, 2022

Image optimization for mobile on CDN

potatotips #80 のLTで発表したもの。

CDN edgeで変換すると便利だけど、avifのご利用は慎重にという話をしたかったけど時間切れになってしまったやつ。

r-plus

December 22, 2022
Tweet

More Decks by r-plus

Other Decks in Technology

Transcript

  1. 14~ (2020~) 16~ (2022~) 4~※ (2011~) 12~ (2021~) Can I

    use? 4.xʹਖ਼͘͠දࣔ͞Εͳ͍όʔδϣϯ͕͋Δ
  2. CoreWebVital - LCP • Largest Contentful PaintͷུɻWebͷSEOʹӨڹ • ͍͍ͩͨը૾͕Ұ൪େ͖͍ࣄ͕ଟ͍ͨΊɺը૾༰ྔ͕ݮΓද͕ࣔ଎͘ͳΕ ͹LCP͕ྑ͘ͳΔ

    • lossyѹॖͨ͠Γɺը૾ͷαΠζΛݮΒ͢ࣄ͕ॏཁͳཁૉͷ1ͭ • Mobileʹ͸ͦͷΑ͏ͳࢦඪ͸ಛʹແ͍͕…
  3. webͱൺֱͨ͠ࡍͷը૾දࣔ • Web • PictureλάͰͷࣗಈతͳରԠঢ়گຖͷϑΝΠϧͷग़͠෼͚ • Τϥʔ࣌ͷonerror JSͰͷfallback • Mobile

    app • ݹ͍ΞϓϦ΋ߟ͑ΔͱදࣔͰ͖ͳ͍ϑΥʔϚοτΛ౉ͯ͠͠·ͬͨ৔߹ද ࣔ͞Εͳ͘ͳΔ • ࣄલͷม׵ʹࣦഊ͓ͯ͠ΓɺͦͷURLʹ͸ϑΝΠϧ͕ଘࡏ͠ͳ͍৔߹΋ಉ༷
  4. Accept header Chrome 108: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8 Firefox 106: image/avif,image/webp,*/* Safari 16※:

    image/webp,video/*;q=0.8,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5 ※macOSͷόʔδϣϯʹΑͬͯavifͷ༗ແ͕มΘΔ ※Safari͸ը૾ͷURLʹ௚઀ΞΫηε͢Δͱը૾ܥͷAcceptʹͳΒͳ͍ text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Acceptϔομʔແ͠ Acceptϔομʔແ͠
  5. Accept header - iOS (Alamo f ireImage) https://github.com/Alamo f ire/Alamo

    f ireImage/blob/4.2.0/Source/Request%2BAlamo f ireImage.swift#L47 • Alamo f ireImageͰImageViewʹը૾Ληο τ͍ͯ͠Δ৔߹ࣗಈͰAcceptϔομʔΛઃ ఆͯ͘͠Ε·͢ • Prefetch౳ͦͷଞͷը૾ϦΫΤετ΋͋Δͷ Ͱ࠷ऴతʹ͸པΒͣʹAcceptϔομʔΛॻ ͘ࣄʹ͠·ͨ͠ • Abcॱιʔτ͞ΕΔͷͰMIMEͷॱ൪͕αʔ όଆ࣮૷ʹΑͬͯ໰୊ʹͳΔࣄ΋ɻ
  6. avif problem - iOS • iOS 16͕ͩavifը૾͕දࣔ͞Εͳ͍ˠޙड़ • ৽نΞϓϦΛ࡞੒͠ద౰ʹUIImageViewʹྲྀ͠ࠐΉͱදࣔ͞ΕΔ •

    ͜ͷࢿྉΛॻ͍͍ͯͯɺίʔυΛݟ͍ͯͨΒAlamo f ireImage͕ ͍࣋ͬͯΔMIMEϦετ(·ͩσϑΥϧτͰ͸image/avif͕௥Ճ͞ Ε͍ͯͳ͍)ʹແ͍MIME͕ฦͬͯ͘ΔͱΤϥʔΛthrow͍ͯ͠ΔՕ ॴΛݟ͚ͭͨͷͰɺAlamo f ireImageͷΞοϓσʔτ(ݱ࣌఺ະϦ Ϧʔε)·ͨ͸addAcceptableImageContentTypes(_:)ϝιουͰͷ௥ Ճ͕ඞཁ https://github.com/Alamo f ire/Alamo f ireImage/blob/4.2.0/Source/Request%2BAlamo f ireImage.swift#L150-L156