Slide 1

Slide 1 text

FRONT-END WEB ARCHITECTURES THAT WON’T BITE (YOU IN THE ASS) Steve Workman @steveworkman

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

HTTPS://GITHUB.COM/MIKKEREN/FIZZBUZZENTERPRISEEDITION

Slide 4

Slide 4 text

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller JavaScript Server & JavaScript HTML & CSS

Slide 5

Slide 5 text

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller JavaScript Server & JavaScript HTML & CSS

Slide 6

Slide 6 text

JQUERY IS NOT THE ANSWER TO GOOD JAVASCRIPT  JavaScript != jQuery  Solves cross-browser compatibility problems  Really useful for AJAX and events  Performance matters – ID selectors are 2.8% of native, tag name selectors are 0.23% of native http://vanilla-js.com

Slide 7

Slide 7 text

Which came first?

Slide 8

Slide 8 text

Form-helpers.js Main.js Charts.js Utilities.js D3.js

Slide 9

Slide 9 text

Dependency Soup RequireJS .NET http://www.stefanprodan.eu/requirejs-for-asp-net-mvc/ Everyone else: http://requirejs.org/ require([“form-helpers”, “utilities”, “d3”], function () { });

Slide 10

Slide 10 text

Modular Testable DRY

Slide 11

Slide 11 text

ES6 features module definitions in the spec

Slide 12

Slide 12 text

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller JavaScript Server & JavaScript HTML & CSS

Slide 13

Slide 13 text

• Can be overkill for smaller projects • “Yet another thing to learn” • Separation of concerns on client-side • Huge maintainability benefits for JavaScript-heavy sites and web apps

Slide 14

Slide 14 text

Use Handlebars / Mustache / Underscore / Jade / [syntax of choice] Separates View from Model You wouldn’t put HTML in your C# or Java classes, so why would you do it in JavaScript?

Slide 15

Slide 15 text

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller JavaScript Server & JavaScript HTML & CSS

Slide 16

Slide 16 text

 CSS is more complicated than it’s ever been, and gets more complicated with every module  Need to be able to re-use the basics – grids, table styles, forms, complex syntax, have common variables, and solve the vendor prefix problem

Slide 17

Slide 17 text

.table-sparkline { .box-sizing(border-box); tbody tr { th { width: 50%;} td { &.sparkline { width: 15%; } &.amount { width: 35%; } } } thead tr { td, th { background-color: @companyLogoBlack; color: @offWhite; font-weight: normal; } } } .table-sparkline { -moz-box-sizing:border-box; box-sizing:border-box; } .table-sparkline tbody tr th { width:50%; } .table-sparkline tbody tr td.sparkline { width:15%; } .table-sparkline tbody tr td.amount { width:35%; } .table-sparkline thead tr td, .table-sparkline thead tr th { background-color:#2f2f2f; color:#f2f2f2; font-weight:400; } Less CSS Output

Slide 18

Slide 18 text

http://gs.statcounter.com/#browser-ww-monthly-201301-201303-map

Slide 19

Slide 19 text

 Yes, it’s awesome  Enforces good web design practices  Makes web development faster • No, you don’t need all of it, or even half of it (always build from source) • Even when optimised, over 70% of CSS selectors are unused • Makes identi-kit websites easily Consider the alternatives Skeleton – http://getskeleton.com Initializr - http://www.initializr.com/ Foundation -http://foundation.zurb.com/

Slide 20

Slide 20 text

http://www.flickr.com/photos/dkeats/5140359468/ - Snake Charmer, Derek Keats http://www.flickr.com/photos/theartguy/3135448990/ - Duct Tape Bow – Aaron Smith http://www.flickr.com/photos/stevendepolo/3703145222/ - Wrapped Gifts – Steven Depolo http://www.flickr.com/photos/jeffsand/3871415191/ - Square Peg, Round Hole – Jeff Sandquist http://www.flickr.com/photos/aidanmorgan/5319367230/ - Chicken and Egg – John Morgan http://www.flickr.com/photos/rene-germany/18978653/ - Six Flags, New England – Rene Schwietzke http://www.123rf.com/photo_11426487_chonburi-thailand--december-4-a-man-puts-his-head-in-crocodile.html - ichbintai - Man puts his head in a crocodile Photo Credits http://www.paconsulting.com/careers/ [email protected] Twitter: @steveworkman Further reading: JavaScript Design Patterns (ebook) http://addyosmani.com/resources/ess entialjsdesignpatterns/book/ JavaScript templates https://developer.mozilla.org/en- US/docs/JavaScript_templates Front-end testing with CasperJS http://robertbasic.com/blog/frontend- testing-with-phantomjs-and-casperjs