Front End Good Practices
Upcoming SlideShare
Loading in...5

Front End Good Practices






Total Views
Views on SlideShare
Embed Views



2 Embeds 24 15 9



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Front End Good Practices Front End Good Practices Presentation Transcript

    • FrontEnd Good PracticesImproving our work!
    • • The Web Browser• The User Experience• The Content Layer• The Visual Layer• The Behavior LayerFrontEndIts parts.
    • Tools
    • Code EditorSublime Text 2, Notepad++, gEdit, etc.
    • Web BrowsersChrome, Firefox, Safari, Opera, IE, Android Browser, Opera Mini
    • Development KitsFirebug, WebKit Developer Tools
    • Firefox ExtensionsWeb Developer, Dust-Me, MeasureIt, YSlow
    • Chrome ExtensionsWeb Developer
    • The Web Browser
    • Web Browser’s partsretrieves resources from the server and visually presents them.
    • Default Stylesheetpresents the content in a reasonable manner.
    • W3C Recommendationfor HTML4
    • But, there aremany Web Browsers with many versions.• Internet Explorer• Chrome• Firefox• Safari• Opera
    • Rendering engineby browser.Engine used byGeckoFirefox, SeaMonkey, Galeon, Camino, K-Meleon, Flock, Epiphany-gecko ... etcPresto Opera, Opera Mobile, Nintendo DS & DSi Browser, Internet ChannelTrident Internet Explorer, Windows Phone 7WebKitSafari, Chrome, Adobe Air, Android Browser, Palm webOS, SymbianS60, OWB, Stream, Flock, RockMelt
    • Reset CSSis used to fit your layout better in those browsers.
    • Reset CSSFirst you have the HTML with default stylesheet.
    • Reset CSSThen adds the reset.
    • Reseted CSS
    • The options to reset
    • Latest Browserversion is where you have to build.• Chrome• Internet Explorer• Firefox• Safari• Opera
    • Browser Sniffinghelps us serving browser appropriate content.• Wurfl• Conditional Comments• Polyfills
    • Wurflis a feature detection technique for regressive enhancement.
    • Conditional Commentswas introduced by IE5.<!doctype html><html><head><!--[if IE]>Match with any version of IE<![endif]--><title>MercadoLibre</title></head><body><p>The basic content</p><!-- Comment --></body></html>
    • Polyfillsis a feature detection technique for regressive enhancement.
    • PolyfillsPlaceholder example.
    • Can I Use?It provides information about browser’s features support.
    • The Content Layer
    • Markup languageis not a programming language.
    • Markup languageis not a design program.
    • HTML firstBe centered at the content and create semantic HTML.
    • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.or<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.orgThe doctypeis required to do cross browser.
    • <!doctype html>The doctypeis required to do cross browser.
    • <!doctype html><html><head><title>MercadoLibre</title></head><body><p>The basic content</p><!-- Comment --></body></html>The doctypeis required to do cross browser.
    • • < can be mixed with tags• > can be mixed with tags• “ the quotes start an attribute• & the ampersand is also reservedEntitiesare used to implement reserved characters.
    • Attributevalues should be between quotes.<p id=”paragraph”>It’s the content</p>Open tag & close tag. Element with content.<img src=”/icon.png” width=”48” alt=”Cut”>Unique tag. Element without content.
    • <!doctype html><html><head><title>MercadoLibre</title></head><body><p>The basic content</p><!-- Comment --></body></html>Commentthe code.
    • Semantic onlyDo not use HTML to gives visual format.<p><font size=”20”>Big</font></p>
    • <p><font size=”20”>Big</font></p><p class=”featured”>Big</p>not recommendedSemantic onlyDo not use HTML to gives visual format.<h1>Big</h1>
    • <p align=”right” >Right</p>Semantic onlyDo not use HTML attributes to gives visual format.
    • <p align=”right” >Right</p><p class=”featured”>Right</p>not recommendedSemantic onlyDo not use HTML attributes to gives visual format.
    • DivitisAvoid unnecessary elements.
    • <p style=”color:#ffffff;”></p>Rules should never go inline
    • <p style=”color:#ffffff;”></p><p class=”featured”></p>not recommendedRules should never go inline
    • Check the markupensures better cross browser at first steps.
    • The Visual Layer
    • !importantCode Selectors SpecificityLayout Hacks
    • CodeComment & Organize
    • /* Comment */selector {property: value;}Commentthe code.
    • /* Header Styles */header {width: 100%;}/* Footer Styles */footer {color: white;}Organizethe code.
    • SelectorsMatching Elements
    • Selectorsare patterns that match against elements in a tree. header {}2. footer p {}3. .featured-box {}4. a:hover {}5. input[type=”submit”] {}
    • ID#featured-news {color: red;}Selector Categoryis used to filter from the relevant rules from the {color: red;}Tagdiv {color: red;}
    • Classes & IDsName considerations.• Do not start with numbers• Do not refer the design “redTitle”• Must be a semantic name
    • html body div h1 span {color: #ff0;}Key Selectoris the part that matches the element, rather than its ancestors.Key Selector
    • * {float: left;}ul * {font-weight: bold;}.header * {color: black;}Avoiduniversal rules.
    • Do Notqualify ID rules with tag names or classes.
    • Do Notqualify class rules with tag names.
    • header {width: 100%;}footer {width: 100%;}Combinethe selectors.header, footer {width: 100%;}
    • Multiple Classesmay make the selector more specific or give it additional weight.
    • SpecificityResolving conflicts
    • Specificityis a mechanism that aids conflict resolution. style attribute2. ID selectors3. Class selectors4. Tag selectors5. at same specificity the latter defined rule take precedence
    • Calculatinga selector’s specificity.,b,c,dcount 1 if is a inline stylequantity of IDquantity of other attributes and pseudo-classesquantity of element and pseudo-elements
    • Selectorsare patterns that match against elements in a tree. header {}2. footer p {}3. .featured-box {}4. a:hover {}5. input[type=”submit”] {}0, 0, 0, 10, 0, 0, 20, 0, 1, 00, 0, 1, 10, 0, 1, 1
    • LayoutDividing & Displacing
    • display: block;inline;inline-block;list-item;table-cell;table-row;none;HTML Elementsby CSS display property.p, div, section, articleimg, strong, a, inputlitd, thtrhead
    • display block<div>Text</div> <div>Text</div>display inline<span>Text</span><span>Text</span>Inline vs BlockHow does display work?
    • Box-Modelmarginborderpaddingcontenttopbottomrightleft
    • StaticIt is the default value for the position property.
    • RelativeRelative value allows move the element from itself.
    • AbsoluteAllows you move the element from the container element.
    • FixedIt fixes the element from the browser.
    • Float & ClearAligning the element from the containers margin.float:left; float:right;clear:both;
    • HacksThe last solution
    • header {margin-bottom: 15px;margin-left: 5px;margin-top: 15px;margin-right: 5px;}Use the shorthandproperty instead expanded one.header {margin: 15px 5px;} {margin: 10px;}
    • Lint the codeCheck the syntax.
    • Images
    • Add the size browser render without waiting for images to download.
    • Do Not re-sizeHow do I deal with cross device images?
    • Compress
    • Requests
    • RequestsDo less request as possible and compress it.• Minifies the CSS and JS files• Join all the CSS and JS files in one file• Cache the files• Do Async request if you can
    • Spritesallows you to do less request by adding many images at one.
    • Web fonticon library allow you don’t use sprites for icons.
    • JavaScript
    • JavaScript engineby browser.Engine used bySpiderMonkey Mozilla FirefoxRhino MozillaCarakan OperaChakra Internet Explorer > 9JScript Internet Explorer < 8V8 ChromeNitro Safari
    • <p onclick=”hideDiv();”></p>Never write obtrusive code
    • <p onclick=”hideDiv();”></p><p id=”overview”></p>not recommendedNever write obtrusive code
    • JS never goes in HEAD<!doctype html><html><head><title>MercadoLibre</title><script>function greet(){alert(“hello world!”);}</script></head><body><p>The basic content</p><!-- Comment --></body></html>
    • <!doctype html><html><head><title>MercadoLibre</title></head><body><p>The basic content</p><!-- Comment --><script>function greet(){alert(“hello world!”);}</script></body></html>JS never goes in HEAD
    • Lint the codeCheck the syntax.
    • The Good PartsDouglas
    • JavaScriptPatternsStoyan
    • Object-OrientedJavaScriptStoyan
    • MaintainableJavaScriptNicholas