front end tooling and performance - codeaholics hk 2015

43
Holger Bartel | @foobartel | CodeaholicsHK April 2015 Meetup FRONT END TOOLING PERFORMANCE FOR/AND

Upload: holger-bartel

Post on 16-Jul-2015

115 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Front End Tooling and Performance - Codeaholics HK 2015

Holger Bartel | @foobartel | CodeaholicsHK April 2015 Meetup

FRONT END TOOLING

PERFORMANCE

🚀

FOR/AND

Page 2: Front End Tooling and Performance - Codeaholics HK 2015

FRONT END DEVELOPMENT IS

EASY!

http://en.wikipedia.org/wiki/Tightrope_walking

FRONT END DEVELOPMENT IS

EASY!

Page 3: Front End Tooling and Performance - Codeaholics HK 2015

OK, MAYBE LOOKS EASY…

OK, MAYBE LOOKS EASY…

Page 4: Front End Tooling and Performance - Codeaholics HK 2015

MAN ON WIRE

Page 5: Front End Tooling and Performance - Codeaholics HK 2015

“It’s Damn Hard!”– Charis Rooda

TURNS OUT…

Page 6: Front End Tooling and Performance - Codeaholics HK 2015

MOST OF THE TIME YOU’LL NEED MORE THAN JUST 3 INGREDIENTS

TO COOK A GREAT MEAL

MOST OF THE TIME YOU’LL NEED MORE THAN JUST 3 INGREDIENTS

TO COOK A GREAT MEAL

Page 7: Front End Tooling and Performance - Codeaholics HK 2015

TODAY, FRONT END DEVELOPMENT SEEMS MORE LIKE

A HUGE BUFFET

TODAY, FRONT END DEVELOPMENT SEEMS MORE LIKE

A HUGE BUFFET

Page 8: Front End Tooling and Performance - Codeaholics HK 2015

THE BACKSTORY

Page 9: Front End Tooling and Performance - Codeaholics HK 2015

SF BAY GUARDIAN, 2003

Page 10: Front End Tooling and Performance - Codeaholics HK 2015
Page 11: Front End Tooling and Performance - Codeaholics HK 2015

DELIVERING THE GOODS IN UNDER 1000MS

https://www.youtube.com/watch?v=E5lZ12Z889k

🚀

Page 12: Front End Tooling and Performance - Codeaholics HK 2015
Page 13: Front End Tooling and Performance - Codeaholics HK 2015
Page 14: Front End Tooling and Performance - Codeaholics HK 2015

Built with Foundation 5 Uses jQuery, jQuery UI, Vanilla JS

& Grunt

MISSEDIN-HKG.COM

Page 15: Front End Tooling and Performance - Codeaholics HK 2015

CSS File Size: 88Kb JS File Size: 213Kb Total Size: 559Kb

DEVELOPMENT

CSS File Size: 3.8Kb JS File Size: 54.3Kb Total Size: 132Kb

PRODUCTION

Page 16: Front End Tooling and Performance - Codeaholics HK 2015

TAMING FRAMEWORK OVERHEAD

Page 17: Front End Tooling and Performance - Codeaholics HK 2015

USING FRAMEWORKS IS OK

B

Page 18: Front End Tooling and Performance - Codeaholics HK 2015

KILL THE LAZY DEVELOPER IN YOU…

Page 19: Front End Tooling and Performance - Codeaholics HK 2015

CSS SPRING CLEANING

Page 20: Front End Tooling and Performance - Codeaholics HK 2015

YOU WANT TO AVOID THIS: 15.689 UNUSED RULES

Page 21: Front End Tooling and Performance - Codeaholics HK 2015

BETTER: 811 UNUSED RULES

Page 22: Front End Tooling and Performance - Codeaholics HK 2015

HAPPY: 55 UNUSED RULES

Page 23: Front End Tooling and Performance - Codeaholics HK 2015
Page 24: Front End Tooling and Performance - Codeaholics HK 2015
Page 25: Front End Tooling and Performance - Codeaholics HK 2015

SO, HOW DO WE GET THERE?

Page 26: Front End Tooling and Performance - Codeaholics HK 2015

TOOLING

Page 27: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT JAVASCRIPT TASK

RUNNER

http://www.gruntjs.com

Page 28: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT-UNCSSRemove unused CSS rules

Page 29: Front End Tooling and Performance - Codeaholics HK 2015

   uncss:  {              dist:  {                  options:  {                      //  ignore:  ['.active',  '.alert-­‐box']                  },                  files:  {                      'css/app.un.css':  ['index.html',  'readpost.php',  'uncss.html']                  }              }          }

Page 30: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT-PROCESSHTMLModify HTML files at build time

Page 31: Front End Tooling and Performance - Codeaholics HK 2015

   <!-­‐-­‐  build:js  js/app.min.js  -­‐-­‐>          <script  src="bower_components/jquery/dist/jquery.min.js"></script>          <script  src="js/jquery.validate.js"></script>          <script  src="js/fastclick.js"></script>          <script  src="js/app.js"  async></script>          <script  src="js/main.js"></script>      <!-­‐-­‐  /build  -­‐-­‐>

Page 32: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT-CONTRIB-UGLIFYMinify files

Page 33: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT-CONTRIB-CSSMINMinify CSS files

This task needs to run a!er UnCSS, otherwise it will un-minify the CSS again.

Page 34: Front End Tooling and Performance - Codeaholics HK 2015

   cssmin:  {              add_banner:  {                  options:  {                      banner:  '/*  Minified  CSS  for  a  happy  day!  */'                  },                  files:  {                      'dist/css/app.min.css':  ['css/app.un.css'],                      'css/app.min.css':  ['css/app.un.css']                  }              }          }

Page 35: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT-STRING-REPLACEFind & Replace Text

Page 36: Front End Tooling and Performance - Codeaholics HK 2015

   'string-­‐replace':  {              inline:  {                  files:  {                      'dist/index.html':  'dist/index.html',                  },                  options:  {                      replacements:  [                          {                              pattern:  '<script  src="js/app.min.js"></script>',                              replacement:  '<script  src="js/app.min.js"  async></script>'                          }                      ]                  }              }          }

Page 37: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT-IMAGEOPTIM

Page 38: Front End Tooling and Performance - Codeaholics HK 2015

<img  alt="Missed  in  HKG"  src=“data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9z…41IDEuMiA4LjcgMjIuNCAyMi40LTguNyAxLjItMC41QzQ5MC43IDkwLjYgNDkzLjggODMuNyA0OTEuNCA3Ny41eiIvPjwvc3ZnPg==“>

SAVINGS OVER PNG: 15KB

Page 39: Front End Tooling and Performance - Codeaholics HK 2015

GRUNT-CRITICALCSSExtract the Above the Fold CSS for your page

Page 40: Front End Tooling and Performance - Codeaholics HK 2015

http://www.perf.rocks

Page 41: Front End Tooling and Performance - Codeaholics HK 2015

ENABLE GZIP IN .HTACCESS

https://h5bp.github.io

Page 42: Front End Tooling and Performance - Codeaholics HK 2015

PERFORMANCE TESTING

http://www.webpagetest.org

http://tools.pingdom.com/fpt/

https://developers.google.com/speed/pagespeed/

https://developer.yahoo.com/yslow/

Page 43: Front End Tooling and Performance - Codeaholics HK 2015

THANKS!

Holger Bartel | @foobartel | CodeaholicsHK April 2015 Meetup

@foobartel [email protected]