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

Performance - Web 前端程式開發實務

Performance - Web 前端程式開發實務

Joseph Chiang

May 02, 2013
Tweet

More Decks by Joseph Chiang

Other Decks in Programming

Transcript

  1. Copyright © 2012 FITPI. All rights reserved. 8FCིି 2 Our

    performance golden rule is: optimize front- end performance first, that's where 80% or more of the end-user response time is spent. Steve Souders Google High Performance Engineer ↌ᅟིିླ༵∱߄భ؊đၹᆜⅴ 3FTQPOTFℭᾇᇏđభ؊ᅝਔ b
  2. Copyright © 2012 FITPI. All rights reserved. ↌ᅟིିᾋṦ۽ऎ ๏ :4MPX

    IUUQEFWFMPQFSZBIPPDPNZTMPX ๏ 1BHF4QFFE IUUQTEFWFMPQFSTHPPHMFDPNTQFFEQBHFTQFFE 3 նᇁῲ䪌׻൞ᄝ⏟´ఖᇏν⊬၂ἠ۽ऎ ෱὜၇ᅶ၂ུ⊵≣ ॖỆᆜ ٳ༅෮ᄝ↌∉ིି ‣↮ğ⊬ఏῲᄝ୆ӈႨ֥↌ᅟ஝஝ु
  3. Copyright © 2012 FITPI. All rights reserved. ↌∉ིି⇊ଢ ๏ $BDIF⏟´ఖ؊aයڛఖ؊a$%/

    ๏ (;JQ↌∉ẖ℻֥ሱọ⇭⅜Ὠᇅ ๏ 㦆ഒ)551⃪֥౰⅂ਈ ๏ ᾞ$44+BWB4DSJQUቋཬ߄ ๏ ⅾோቋࡄ߄ ๏ ↥؁ೖ≘ೆ 6 Ᾱਙԛ၂ིུିڿΆ֥ᇗề
  4. Copyright © 2012 FITPI. All rights reserved. $%/ ๏ $POUFOU%FMJWFSZ/FUXPSLb

    ๏ 4FSWFS⟦ඇᄝಆൗࢸ֥ૄἠֹٚb ❖ "NB[POࠇ"LBNFJ׻ႵՎሿ ڛ↩b ๏ ♶⚧ῲჷ↌ᅟ֥+4$44*NBHFT֩僯Ⅲẵσb ๏ ℳႨᧄॴἽڛ↩֥ᇏն྘↌ᅟb ❖ ২ೂ:BIPP (PPHMF֩ಆ౯߄↌ᅟb ๏ ൐Ⴈᆀթ౼ቋ࣍ࠇ෎؇ቋॹ֥$%/4FSWFSđط٤ჰ ൓ẵσթ٢ֹ֥ٚb 7
  5. Copyright © 2012 FITPI. All rights reserved. 9 ỚῘứ֥႕⇉ ๏

    $%/၂֊ሂ֞ẵσđ≁℟὜٢୍ၛഈb ๏ ℭᾇ⤨҂὜ཟ୆֥යڛఖᇗྍ෬౼ẵσb ๏ Ῐứᆀླေڿṉẵ଀ࠇࡆഈϱὂč২ೂℭᾇՄὸa ࠇWFSTJPOĎҌି⃸$%/ᇗሂ⊷ਘ ❖ ჰ൓ẵσğGPPKT ❖ ڿṉẵ଀ğGPP@SKT ❖ ᄹࡆ(&5Ṛ⅂ğGPPKT S
  6. Copyright © 2012 FITPI. All rights reserved. (;JQ%FGMBUF 10 http://www.sebkuehn.com/blog/seo/speed-up-your-website-for-better-seo/

    8FC4FSWFS∻#SPXTFSᾇ֥ࡆࢳ⇭⅜Ὠᇅ ೏ᆦჱ(;JQ%FGMBUFđ὜ᾞ໓ሳẵ⇭⅜㬪#JOBSZẖෂ ᄝ#SPXTFS؊ࢳ⇭⅜a₹ῥॖᾳസޓ؟Ć
  7. Copyright © 2012 FITPI. All rights reserved. (;JQ%FGMBUF 11 <IfModule

    mod_deflate.c> DeflateCompressionLevel 6 AddOutputFilter DEFLATE html htm xml css js php AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php </IfModule> ໓ሳ ྘֥ẵσ׻ॖၛ℟ק
  8. Copyright © 2012 FITPI. All rights reserved. 㦆ഒ)551⃪౰⅂ਈ 12 ๏

    )551⇐ק֥3FRVFTU3FTQPOTF 5$1  ൞υἹ֥a∣ἐམḰم㦆ഒb ๏ 㦆ഒ⃪౰⅂ਈ֥ٚൔնᇁೂ༯ğ ❖ $444QSJUFTކ⟸୆֥ⅾோ ❖ ҆ٳⅾோ㍇Ⴈ%BUB63* ❖ ކ⟸+BWB4DSJQU$44ẵσ ❖ ⅾோ-B[Z-PBE࠯ℿ ๏ ֩༯὜ῲࢺℚކ⟸ࠣ-B[Z-PBE֥࠯ℿ
  9. Copyright © 2012 FITPI. All rights reserved. ⅾோቋࡄ߄ 13 ๏

    (*'೤aᆦჱ๩ૼ *OEFY aọ὎b ๏ 1/(೤aᆦჱ϶๩ૼ "MQIB ❖ ቋℳކ↌∉൐Ⴈ֥ⅾẵ۬ൔ ❖ "EPCF'JSFXPSLT൞ື၂ᆦჱ⊨㍤㬪1/(϶๩ૼ֥ℂⅴb ๏ 1/(⅂Ϥ↋೤aᆦჱ϶๩ૼ "MQIB b ❖ ♶≗ⅾཞč٤ᅶோĎ ๏ +1(ᾹℳކႨᧄᅶோb ๏ ⇢≢ⅾோ۬ൔ֥喆ࣁჰ≣ğ ᅶோႨ+1&(aọ὎Ⴈ(*'aః∸ಆ҆Ⴈ1/(b ๏ ⅾோ䥰Ⴕޓ؟Ⴈ҂֥֞⊷⇫đॖၛ๩Ἶ۽ऎࢆ֮ᆜⅴ4J[F IUUQTHJUIVCDPNKPTFQIKPQUJNH
  10. Copyright © 2012 FITPI. All rights reserved. ⇢≢.*/* ๩Ἶ℟קẵ ᾞ؟ἠẵσކ⟸aቋཬ߄

    ֥Ῐứὔ࣢۽ऎ http://www.flickr.com/photos/prettypony/2644225789/ https://github.com/josephj/mini 16
  11. Copyright © 2012 FITPI. All rights reserved. 21 ‣↮ğ.JOJ ๏

    ⃪༯≘NJOJaࢳ⇭⅜֞$="QQ4FSW=XXX=MJC IUUQGFDMBTTDPNMBCQFSGPSNBODFNJOJ[JQ ๏ ᄝ"QBDIF℟קẵ䥰ᄹࡆ‥ྛ ླᇗ⬏ "MJBTNJOJ$="QQ4FSW=XXX=MJC=NJOJ=NJOJ@XFCQIQ 4FU&OW%&7@3005$="QQ4FSW=XXX ๏ ྍᄹ၂ἠ.JOJ℟קẵaᄹࡆ၂ུ+4$44ẵ $="QQ4FSW=XXX=DPOG=NJOJ=NJOJYNM ๏ Ⴈၛ༯ٚൔुु൞ڎႵ℟קӮۿğ IUUQMPDBMIPTUNJOJ UZQFUZQFNPEVMFNPEVMF
  12. Copyright © 2012 FITPI. All rights reserved. ⇢≢.JOJGZ ๏ IUUQDPEFHPPHMFDPNQNJOJGZ

    ๏ .JOJ൞๩Ἶ℟קẵa֌.JOJGZ≣൞ᆰࢤạ↌ ᆶᆷקb ๏ ∻:6*$PNCP)BOEMFS֥ቔم၂ᇁ ๏ ὜Ⴕ(&5ṵ؇ཋᇅ↜ⅳ ,_, b 22 http://<your host>/minify?f= ẵσ1֥ਫ਼῅ ẵσ2֥ਫ਼῅  ẵσn֥ਫ਼῅
  13. Copyright © 2012 FITPI. All rights reserved. 23 ‣↮ğ.JOJGZ ๏

    ⃪༯≘NJOJGZaࢳ⇭⅜֞$="QQ4FSW=XXX=MJC IUUQGFDMBTTDPNMBCQFSGPSNBODFNJOJGZ[JQ ๏ ᄝ"QBDIF℟קẵ䥰ᄹࡆ‥ྛ ླᇗ⬏ "MJBTDPNCP$="QQ4FSW=XXX=MJC=NJOJGZ=NJO= ๏ ྩڿ℟קẵ $="QQ4FSW=XXX=MJC=NJOJGZ=NJO=DPOGJHQIQ ๏ Ⴈၛ༯ٚൔुु൞ڎႵ℟קӮۿğ IUUQMPDBMIPTUDPNCP GGJMF GJMF GJMF
  14. Copyright © 2012 FITPI. All rights reserved. ≘ೆຓ҆4DSJQU 25 ๏

    ҂ܵ൞TDSJQUTSDࠇMJOLISFG׻὜؁ೖᗥ⇟ ⤨ಸ֥↾ൕb ❖ http://f2eclass.com/lab/performance/blocking- javascript.html ๏ ֌ཞ൞(PPHMF"OBMZUJDTࠇ'BDFCPPL4PDJBM 1MVHJOิ܂ⅶೆ୆↌ᅟ֥ჰ൓׻҂὜؁ೖb ๏ ὕὸ֤EPDVNFOUDSFBUFॖၛࡹ৫ᾳề֥ٚൔ Ĥၛ≾∄֥ٚൔ≘ೆຓ҆4DSJQUࣼॖၛх૧؁ ೖb
  15. Copyright © 2012 FITPI. All rights reserved. ཟ'#⇥↮↥؁ೖ 26 <script

    type=”text/javascript”> (function () { var el = document.createElement("script"); el.type = "text/javascript"; el.src = "要載⼊入 JavaScript 的 URL"; el.async = true; document.getElementsByTagName("head")[0].appendChild(el); }()); </script> http://f2eclass.com/lab/performance/non-blocking-javascript.html
  16. Copyright © 2012 FITPI. All rights reserved. 28 Ⴕޓ؟ⅾோ֥∉૫ ๏

    ೏↌∉ᇏႵޓ؟ⅾோč২ೂữ২↌ᅟĎa໡ⁿ ׻ႨẖⅼJNHTSDቓ≘ೆbằồ౼Վ↌∉ℭ ෮Ⴕ֥ⅾோ׻൞၂⟸༯≘֥b ๏ ֌൐Ⴈᆀॖିᆺुഒ҆ٳ֥ⅾa㢻ु֥֞ⅾࣼ শỷਔ≘ೆ֥ੀਈਔ ๏ :6*֥*NBHF-PBEFS۽ऎğằ൐Ⴈᆀॹ⚂֞ ॖ൞⃯თຓ֥ⅾோℭaҌῘ൓≘ೆb
  17. Copyright © 2012 FITPI. All rights reserved. :6*֥*NBHF-PBEFS ๏ х૧൐ႨJNHaڿႨEJWaᾞⅾẵਫ਼῅ၛ

    TUZMF֥CBDLHSPVOEJNBHFℾྟ℟קb ๏ ቅᆸⅾோ↾ൕğᄝ$44ᇏ℟קⅾோ㬪 CBDLHSPVOEOPOFJNQPSUBOU ๏ :6* VTF൐ႨJNBHFMPBEFSଆ⊾ ๏ OFX:*NH-PBE(SPVQ \ GPME%JTUBODFὖẈ⃯ए  DMBTT/BNFEJW֥DMBTT/BNF ^  29 ‣↮ğhttp://f2eclass.com/lab/performance/imageloader.php
  18. Copyright © 2012 FITPI. All rights reserved. 30 ིି3FWJFX ๏

    భ؊ᅝਔ֥ồ౼ℭᾇb ๏ ೂޅᾋṦ↌∉ིିğ:4MPX1BHF4QFFE ๏ భ؊Ⴕଧུӈᾖིି⇊ଢĤ ๏ ೂޅॹ෎ڿΆ≾ིུିĤ