Slide 1

Slide 1 text

os desafios do desenvolvimento de front-end em um e-commerce @shiota 2013

Slide 2

Slide 2 text

olá! speakerdeck.com/eshiota github.com/eshiota @shiota

Slide 3

Slide 3 text

front-end engineer @

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

DEV

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

e-commerce 101 em alguns slides

Slide 9

Slide 9 text

=)

Slide 10

Slide 10 text

taxa de conversão dos usuários que entram no site, quantos finalizam uma compra?

Slide 11

Slide 11 text

ticket médio em média, quanto os usuários gastam por compra?

Slide 12

Slide 12 text

=) taxa de conversão × ticket médio =

Slide 13

Slide 13 text

taxa de conversão × ticket médio = $

Slide 14

Slide 14 text

= $ =)

Slide 15

Slide 15 text

= ? =)

Slide 16

Slide 16 text

complexo indeciso exigente inexperiente decidido cuidadoso experiente

Slide 17

Slide 17 text

ser humano, como todos nós =)

Slide 18

Slide 18 text

o que faz o usuário abandonar o carrinho?

Slide 19

Slide 19 text

alto custo de frete 44% $

Slide 20

Slide 20 text

não estão prontos para finalizar ? 41%

Slide 21

Slide 21 text

produtos muito caros 25% $

Slide 22

Slide 22 text

guardam para depois 24%

Slide 23

Slide 23 text

não mencionou claramente o frete 22% ?

Slide 24

Slide 24 text

sem guest checkout 14%

Slide 25

Slide 25 text

formulário com muitas informações 12%

Slide 26

Slide 26 text

checkout complexo 11%

Slide 27

Slide 27 text

website lento 11%

Slide 28

Slide 28 text

taxas extras 8%

Slide 29

Slide 29 text

falta de opções de pagamento 7%

Slide 30

Slide 30 text

entrega demorada 6%

Slide 31

Slide 31 text

spam de ofertas 6%

Slide 32

Slide 32 text

site não funciona 5% =(

Slide 33

Slide 33 text

como o front-end pode melhorar a conversão?

Slide 34

Slide 34 text

site não funciona 5% website lento 11% checkout complexo 11% formulário com muitas informações 12%

Slide 35

Slide 35 text

velocidade da página interface estável detalhes = emotion design validação de novas hipóteses

Slide 36

Slide 36 text

desafios de front-end (agora a palestra começa =P)

Slide 37

Slide 37 text

múltiplos desenvolvedores desenvolvimento escalável performance client-side testes a/b

Slide 38

Slide 38 text

trabalhando com vários desenvolvedores

Slide 39

Slide 39 text

trabalhar em equipe é difícil... =(

Slide 40

Slide 40 text

aspas simples × aspas duplas

Slide 41

Slide 41 text

ponto e vírgula no JS × sem ponto e vírgula

Slide 42

Slide 42 text

JavaScript × CoffeeScript

Slide 43

Slide 43 text

(JavaScript, claro)

Slide 44

Slide 44 text

(com ponto e vírgula)

Slide 45

Slide 45 text

... mas cada um pode ter uma visão diferente e complementar. =)

Slide 46

Slide 46 text

code smell performance sintaxe arquitetura

Slide 47

Slide 47 text

mantenha um code standard para o time.

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

consistência, legibilidade, sem bikeshed.

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

git + pull requests

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

qualquer um revisa, qualquer um comenta.

Slide 54

Slide 54 text

diferentes visões, mais erros detectados.

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

o conhecimento é disseminado pelo time.

Slide 57

Slide 57 text

todos ficam mais criteriosos com o que fazem.

Slide 58

Slide 58 text

desenvolvimento escalável e testável

Slide 59

Slide 59 text

desenvolvimento ágil: mudanças precisas, altos ganhos.

Slide 60

Slide 60 text

melhorias são constantes, e nada é 100% definitivo.

Slide 61

Slide 61 text

o código deve ser facilmente alterável/adaptável.

Slide 62

Slide 62 text

dica 1 usem pre-processors de CSS. sério. agora. já. eu espero.

Slide 63

Slide 63 text

sass +

Slide 64

Slide 64 text

variáveis, mixins e funções

Slide 65

Slide 65 text

/********************************************************************* * * Variables Module * * All constants that will be used through the styles must be * defined here. * *********************************************************************/ $TEXT_COLOR : #555; $DISCOUNT_COLOR : #ef6565; $LIGHT_COLOR : #fefafa; $SELECTION_BACKGROUND : #41bdce; $SELECTION_COLOR : #fff; $LINK_COLOR : #447f87; $LINK_HOVER_COLOR : #41bdce; $LINK_ACTIVE_COLOR : #447f87; $ERROR_BACKGROUND : #fffaad; $LIGHT_BACKGROUND : #fefefa; $SITE_WIDTH : 978px; $FOOTER_HEIGHT : 777px; $PURPLE : #905194; $ORANGE : #fbb100;

Slide 66

Slide 66 text

/********************************************************************* * * Mixins Module * * All general purpose mixins are defined here. * *********************************************************************/ /********************************************************************* * =Clearfix *********************************************************************/ @mixin clearfix { &:after { clear: both; content: " "; display: block; font-size: 0; height: 0; visibility: hidden; } zoom: 1; } /********************************************************************* * =Image replacement * * `display` property should be declare on the element, not here * on the mixin. Element must have fixed width and height. *********************************************************************/ @mixin img_replacement { text-indent: 100%; overflow: hidden; white-space: nowrap; }

Slide 67

Slide 67 text

/********************************************************************* * * Functions Module * * Custom functions used by the application * *********************************************************************/ // Returns unitless number @function remove-unit($number) { $unit: unit($number); $one: 1; @if $unit == "px" { $one: 1px; } @if $unit == "em" { $one: 1em; } @if $unit == "%" { $one: 1%; } @return $number / $one; } // Returns flexible value // Returns `em` by default, accepts `%` as format. @function flex($target, $context: 14, $unit: "em") { $size: remove-unit($target) / remove-unit($context); @if $unit == "em" { @return #{$size}em; } @if $unit == "%" { @return percentage($size); } } // Alias to `flex` function, using `%` as format. @function perc($target, $context) { @return flex($target, $context, "%"); } // Alias to `flex` function, using `em` as format. @function em($target, $context: 14) { @return flex($target, $context, "em"); }

Slide 68

Slide 68 text

estilos modularizados em partials

Slide 69

Slide 69 text

app/ assets/ stylesheets/ base/ _functions.scss _mixins.scss _variables.scss ui/ _breadcrumb.scss _carousel.scss _dentedBox.scss _flashMessage.scss

Slide 70

Slide 70 text

/******************************************************************************* * * UI > Breadcrumb * * General styles for the breadcrumb. * *******************************************************************************/ .breadcrumb { font-size: em(12px); line-height: em(21px, 12px); text-transform: uppercase; color: #444; width: 978px; } .breadcrumb a, .breadcrumb a:visited, .breadcrumb a:active { color: #444; text-decoration: none; } .breadcrumb a:hover { color: #444; text-decoration: underline; } .breadcrumb .separator { padding: 0 3px; }

Slide 71

Slide 71 text

/******************************************************************************* * * UI > Loader * * Animated loader for AJAX requests * *******************************************************************************/ @mixin loader_sprite_position($xoffset, $yoffset) { background-position: sprite-position($icon-sprite, loader_sprite, $xoffset, $yoffset); } .loader { width: 25px; height: 25px; display: none; } .loader b { display: block; width: 25px; height: 25px; background-image: sprite-url($icon-sprite); } .loader b, .loader .f1 { @include loader_sprite_position(-10px, -10px); } .loader .f2 { @include loader_sprite_position(-45px, -10px); } .loader .f3 { @include loader_sprite_position(-80px, -10px); } .loader .f4 { @include loader_sprite_position(-115px, -10px); } .loader .f5 { @include loader_sprite_position(-150px, -10px); } .loader .f6 { @include loader_sprite_position(-185px, -10px); } .loader .f7 { @include loader_sprite_position(-220px, -10px); } .loader .f8 { @include loader_sprite_position(-255px, -10px); }

Slide 72

Slide 72 text

geração automática de sprites acelera o desenvolvimento.

Slide 73

Slide 73 text

$icon-sprite: sprite-map("icon/*.png", $spacing: 16px, $repeat: no-repeat, $layout: vertical);

Slide 74

Slide 74 text

$icon-sprite: sprite-map("icon/*.png", $spacing: 16px, $repeat: no-repeat, $layout: vertical);

Slide 75

Slide 75 text

/* Compass sprite function receives the map variable and image as arguments */ background: sprite($icon-sprite, arrow_dropdown) no-repeat; /* Compiled CSS */ background: url(/assets/icon-s5dab8c2901.png) -40px -158px no-repeat;

Slide 76

Slide 76 text

função de inline image economiza requests.

Slide 77

Slide 77 text

/* Compiled CSS */ background: #f5f3fb url('data:image/ png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAQCAMAAAAcVM5PAAAAGXRFWHRTb2Z0d2FyZQBBZG9 iZSBJbWFnZVJlYWR5ccllPAAAAAlQTFRF5+TW////////4qZUpQAAAAN0Uk5T// 8A18oNQQAAACBJREFUeNpiYGBgAgMGBkYog4mJXAbILAiDkVxzAAIMAEMOAPMId2OWAAAAAElFTkSuQmCC ') repeat; /* Generates a base64 image */ background: #f5f3eb inline-image("bg_dots.png") repeat;

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

(seja criterioso)

Slide 80

Slide 80 text

dica 2 módulos: poucas linhas, comportamentos isolados e extensíveis.

Slide 81

Slide 81 text

estrutura base (reset, base styles) grid padrões módulos módulos contextualizados

Slide 82

Slide 82 text

css do módulo

Slide 83

Slide 83 text

/******************************************************************************* * * UI > Loader * * Animated loader for AJAX requests * *******************************************************************************/ @mixin loader_sprite_position($xoffset, $yoffset) { background-position: sprite-position($icon-sprite, loader_sprite, $xoffset, $yoffset); } .loader { width: 25px; height: 25px; display: none; } .loader b { display: block; width: 25px; height: 25px; background-image: sprite-url($icon-sprite); } .loader b, .loader .f1 { @include loader_sprite_position(-10px, -10px); } .loader .f2 { @include loader_sprite_position(-45px, -10px); } .loader .f3 { @include loader_sprite_position(-80px, -10px); } .loader .f4 { @include loader_sprite_position(-115px, -10px); } .loader .f5 { @include loader_sprite_position(-150px, -10px); } .loader .f6 { @include loader_sprite_position(-185px, -10px); } .loader .f7 { @include loader_sprite_position(-220px, -10px); } .loader .f8 { @include loader_sprite_position(-255px, -10px); }

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

css do módulo contextualizado

Slide 87

Slide 87 text

// On ui/_buttons.scss .bt-wrapper .loader { position: absolute; z-index: 4; right: 20px; top: 50%; margin-top: -9px; } // On modules/_checkoutAddressForm.scss .address-form .cep-input .loader { position: absolute; right: -33px; top: em(29px); }

Slide 88

Slide 88 text

javascript enxuto, auto-contido.

Slide 89

Slide 89 text

// Implements the animated loader for AJAX requests // Loader constructor // // * `placement`: Function that determines the loader's placement ns("EDEN.ui.Loader", function (placement) { if (!(this instanceof EDEN.ui.Loader)) { return new EDEN.ui.Loader(placement); } this.frame = 1; this.framesQty = 8; this.stack = []; this.animating = false; this.$loader = $("
"); this.$renderer = this.$loader.find("b"); this.placement = placement; this.init(); }); EDEN.ui.Loader.prototype = { // Properties // ---------- // Animation speed (in frames per second) fps : 20, // Fading speed fadeSpeed : 150, // Public methods // --------------

Slide 90

Slide 90 text

testável!

Slide 91

Slide 91 text

describe("EDEN.ui.Loader", function () { var Loader = EDEN.ui.Loader; beforeEach(function () { loadFixtures("loader.html"); }); afterEach(function () { $("body").find(".loader").remove(); }); it("accepts instance creation without new operator", function () { var newLoader = Loader(); expect(newLoader).toBeInstanceOf(Loader); }); it("inits the loader on creation", function () { var loader , oldInit = EDEN.ui.Loader.prototype.init ; EDEN.ui.Loader.prototype.init = jasmine.createSpy(); loader = new Loader(); expect(loader.init).toHaveBeenCalled(); EDEN.ui.Loader.prototype.init = oldInit; }); it("appends the loader to body as a default", function () { var loader = new Loader(); expect($("body").find(".loader").length).toEqual(1); }); it("appends the loader through an argument function", function () { var loader = new Loader(function ($loader) { $("#loader-placeholder").append($loader); }); expect($("#loader-placeholder").find(".loader").length).toEqual(1); }); });

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

dica 3 javascript desacoplado e modularizado

Slide 94

Slide 94 text

mediator: ponto central de comunicação via pub/sub

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

cartReviewModule.js checkoutModule.js Cart.js CartView.js CartProxy.js installmentSelector.js couponForm.js ShippingAddressSelector.js AddressSelector.js

Slide 114

Slide 114 text

appMediator.js

Slide 115

Slide 115 text

cartReviewModule.js checkoutModule.js Cart.js installmentSelector.js couponForm.js ShippingAddressSelector.js appMediator.js

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

você não precisa saber tudo isso de primeira.

Slide 125

Slide 125 text

addyosmani.com/largescalejavascript

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

aprenda javascript antes de se focar em um framework.

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

performance client-side

Slide 130

Slide 130 text

css/javascript minification/compression

Slide 131

Slide 131 text

lazy-load everything! o/

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

sprites e imagens inlines

Slide 134

Slide 134 text

sass +

Slide 135

Slide 135 text

não abuse de font-faces

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

testes a/b

Slide 138

Slide 138 text

No content

Slide 139

Slide 139 text

No content

Slide 140

Slide 140 text

isole os estilos e JS em classes, partials e módulos totalmente separados

Slide 141

Slide 141 text

Slide 142

Slide 142 text

/******************************************************************************* * =Menu A *******************************************************************************/ .site-header-old .user-menu { position: absolute; right: perc(261px, $SITE_WIDTH); cursor: pointer; width: 213px; height: 63px; overflow: hidden; z-index: 600; } /******************************************************************************* * =Menu B *******************************************************************************/ .site-header-new .user-menu { position: absolute; right: perc(261px, $SITE_WIDTH); width: perc(150px, $SITE_WIDTH); height: em(63px); overflow: hidden; z-index: 600; }

Slide 143

Slide 143 text

AB-TESTING.md - como remover a versão perdedora

Slide 144

Slide 144 text

# A/B Testing on Baby Site This document lists all A/B tests currently being run on the project, and shortly introduces the method being used. ## Tests currently being run ### Site-wide #### Header design version * Test name: `header-version` * Starts at: `ApplicationController`, on `:before_filter` * Goal: When user goes to a success checkout page * Ends at: `orders#success` view * PR/Commits: [#664](https://github.com/Baby-com-br/troy/pull/664) To remove this test: * Remove the `new_header?` method and its `:helper_method` on `application_controller.rb` * Remove the `header_version` method and its `:helper_method` on `application_controller.rb` and ALL its calls. * Consolidate the correct `render` calls on `layouts/_header.html.erb` and `layouts/_site_menu.html.erb` * Remove the `site-header-<%= header_version %>` class on `layouts/_header.html.erb` * Remove the `header-version-<%= header_version %>` class on `layouts/_head.html.erb`, on the `` tag * Remove the `finished` call on `baby-site/app/views/orders/success.html.erb` * On `modules/_mainSearchForm.scss`, remove the entire block related to the loser version, and on the winner version: (1) remove the comment header about the A/B test, (2) unprefix all selectors by removing either `.site-menu` (if the old header won) or `.site-header` (if the new header won) * On `layout/_user_menu.scss`, remove the entire block related to the loser version, and on the winner version: (1) remove the comment header about the A/B test, (2) unprefix all selectors by removing either `.site-header-new` (if the old header won) or `.site-header-old` (if the new header won) * On `ui/_section_header.scss`, remove the `.header-version-old .section-titles` and `.header-version-new .section-titles` blocks, and use the winner padding on `.section-titles`. * On `sections/_profile.scss`, remove the `.header-version-old .profile-header .site-menu` and `.header-version-new .profile-header .site-menu` blocks, and use the winner padding on `.profile-header .site-menu`. * On `layout/_main.scss`, delete the `.header-version-old .site-menu-container` block.

Slide 145

Slide 145 text

shiota, um dev front-end precisa saber back-end?

Slide 146

Slide 146 text

fulano(a), eu preciso saber cozinhar ou lavar roupa?

Slide 147

Slide 147 text

não, mas ajuda, né? ;D

Slide 148

Slide 148 text

você não precisa ser um nando vieira.

Slide 149

Slide 149 text

saber back-end melhora seu código.

Slide 150

Slide 150 text

saber back-end lhe dá mais controle.

Slide 151

Slide 151 text

saber back-end melhora a comunicação.

Slide 152

Slide 152 text

quando você deixa de perguntar apenas "como vou fazer isso" e passa a perguntar "como vou fazer isso da melhor maneira"...

Slide 153

Slide 153 text

... você está no caminho certo.

Slide 154

Slide 154 text

divirta-se. sempre. =)

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

obrigado! speakerdeck.com/eshiota github.com/eshiota @shiota