Front End Development
2-Day schedule - Day 1
-
What is the web?
-
What does front end mean?
-
The Ages of the Web
-
What is the role of the client?
-
HTML5 & Semantics
-
CSS, Styling & best practices
-
Bootstrap / Boilerplate
-
JavaScript the language
-
jQuery
-
Ajax
-
Exercise
2-Day schedule - Day 2
-
Client side templating
-
OOP Patterns in JavaScript
-
Debugging JavaScript
-
Front End / Back End architectures
-
Structuring your Application
-
Intro to Backbone
-
Integrating with Kinvey
-
Building a music-twitter clone
What is the Web?
The world wide web is a system of interlinked
hypertext documents accessed via the Internet. With a
web browser, one can view web pages that may contain
text, images, videos, and other multimedia and navigate
between them via hyperlinks.
The Web is Content
What can you do
on the web?
Just about anything...It's no longer just sites of text. Bookcase
The web is....
Whatever you want to build.
The Good:
If you can dream it,
you can build it
...and deliver it to Billions of people instantly
The Bad:
There's a lot to learn
The Ages of the Web
-
1991-1998: The HTML Age
-
1999-2005: The Lamp Age
-
2006-2009: The Ajax Age
-
2010-??: The JavaScript Age
-
What is
"Front end"?
A set of technologies, guided by standards used on the client.
Front-end technologies
-
HTML
-
CSS
-
JavaScript
-
Data-transport (XML,JSON, HTML)
What's the point of each?
-
HTML - Semantics, Content, Information, Data
-
CSS - Layout and Styling
-
Javascript - Create Dynamism, interaction
-
Data-transport - Transmit information, transform into HTML w/ JavaScript
What is
"The Client"?
Usually - the browser (Chrome, Firefox, Safari, IE)
What does the client do (simplified)?
Look-up a domain, get an IP address, make a HTTP request, make sub requests, download a page ...
nslookup reddit.com
...
telnet 204.245.162.17 80
Trying 204.245.162.17...
Connected to a204-245-162-17.deploy.akamaitechnologies.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.reddit.com
...
.. what does the client do (cont.)?
-
Parses the page, creates the DOM
-
Start downloading assets in parallel (to a per domain limit)
-
Executes JavaScript as it come across it (page stops rendering at JavaScript)
-
Finishes parsing DOM / JavaScript
-
Fires a DOM Ready event (depends on browser)
-
Finishes downloading pages
-
Fires window.onload
HTML
Hypertext Markup Language
HTML is a markup language, which means you're annotating (marking up) plain text to give it structure and meaning, similar to the way you would underline or make notes in a book.
HTML "1.0"
-
Original draft from 1992
-
20 Tags, including: section, h1-h6, p, a, menu, ul, ol, dir, li, dl dt, dd
-
How stuff was displayed was left up to the browser
-
Was more concerned with “Semantic” markup of documents
The Browser War, Round 1
-
Mozilla vs. Microsoft.
-
Started adding features fast and furious
-
Lots of incompatabilities
XHTML
-
Reaction to “looseness” of HTML
-
A XHTML page is a valid XML document
-
In XHTML Strict, document won’t render if there’s a mistake in the HTML
-
Boring & Painful...Coming down from the W3C
HTML5 and The New Hope
-
Previous versions of HTML came from the IETF (Now Defunct) and W3C
-
2004: There was a rebellion over XHTML (non-backwards compatible version of HTML)
-
WHATWG Formed (Apple, Mozilla, Opera)
-
2007: Adopts HTML5, drops XHTML

Last numbered version of HTML
Browser makers driving features
Feature coming fast and furious
Browser Wars Round #2
New in "HTML5"
-
New Semantic Tags
-
Hardware Accelerated 2D + 3D Graphics
-
CSS3 - visual goodies, transitions
-
Audio, Video
-
WebSockets
-
Local Storage
-
Offline Storage
-
SVG
-
New Events (touch, orientation, accel)
-
Geolocation (via GPS)
-
WebRTC
Tags
HTML tags usually come in pairs
<head> </head>
In the industry we refer to these as
start tag and end tag or
open tag and close tag
Tags
In HTML you can write just the opening tag and it will often work like:
<h1> Headline
<p> Body text.
Don’t do this. Always use open and close or single tags.
Attributes
Tell the browser about your content
HTML tags/elements can have attributes
Attributes are always specified in the start tag
Attributes come in name/value pairs like: name="value"
-
<element name = "value">
Attributes
Available on almost tags
CLASS - this defines one or more CSS class names to assign to the tag.
ID - this defines a unique identifier that uniquely refers to this one tag.
STYLE - this defines the CSS styles to use for this particular element.
others: href, src, data-*
HTML5 Semantic Structure
HTML5 Semantic Tags
Most Common Tags
-
<head> = Meta Info
-
<body> = Site Content
-
<header> = Header (Head area of the site)
<nav> = Navigation (Menu/Navigation Area)
<section> = Section, organizing similar content
<article> = Article, self-contained piece of content
<footer> = Footer Area
<aside> = Content ancillary to the main content (sidebar, ad)
how you might use these tags
Writing Good HTML
"A Semantic Chop"
The Goals
-
HTML tags used in Meaningful ways
-
Validating markup
All dynamic interactions added “unobtrusively” (usually via jQuery)
Reminder! your HTML is not your design CSS Zen Garden
CSS
Cascading Style Sheets
-
Used for “presentation” of your HTML
-
Controls the styles of your page
-
Also Controls the layout of your page (where stuff is positioned)
-
Can have different styles different media formats (eg. print and screen) stylesheets for
What is a style?
Available selectors
-
name of element (e.g. p, div, h1)
-
class name prefixed with a period (.)
<div class=‘my-class-name’>..</div>
= .my-class-name { ... }
-
element id prefixed with a pound sign (#)
<div id=‘my-id’>..</div>
= #my-id{ ... }
Selectors
Selector combinations
-
Can have a declaration apply to multiple
styles with a comma (,)
- .my-class-one, .my-class-two { color:red; }
-
Can “Cascade” styles with spaces
-
Can select only "child" styles with spaces
-
Psudeo-classes that apply to elements in certain conditions
- a:hover{ color:blue; } /* only links we are hovering over */
a:visited> { color:red; } /* links we've visited already */
p:first-child > { color:red; } /* the first paragraph in a container */
-
Also can select by arbitrary attributes
- input[type=radio]{ color:blue; } /* only radio buttons */
Selector Combination Exercise
Cascading - What Color?
Cascading Hierarchy: 999
-
Inline style (those defined directly with a style='....' attribute in the tag)
-
Number of ID selectors (hundreds digit)
-
Number of Class selectors (tens digit)
-
Number of tag selectors (ones digit)
-
Order of appearance last to first
-
Style inheritance
Laying out a page w/ CSS
You're on your own...
CSS3 Stuff
CSS Transitions Example
More Examples
CSS3 Animations
-
Are defined with keyframes
-
Have a name
-
Can have a number of other properties including direction, repeat, duration
-
CSS3 Animations Example
You'll need all your prefixes here! (-webkit, -moz, -ms) - only showing webkit for brevity
HTML / CSS Best practicies
1.Organizing Your CSS
-
Start with your reset
-
Set your body
-
Set your base element styles (p, h1, h2, blockquote)
-
Set your reusable class styles
-
Set your layout styles
-
Set your module styles (additional sub-themes like blogs,custom pages, etc )
2. Don't write CSS!
Use a pre-processor
Pre-processor will let you write reusable code with abstractions.
-
LESS - Less CSS
-
Sass - Syntactically Awesome Stylesheets
understand and use! (what you need)
Don't reinvent the wheel!
JavaScript
A Little Demo
The goal is to understand everything in here by the end of class today
Javascript Housekeeping
Hello World!
Call the built in 'alert' function and have it say "Hello World!" We don't use this all that often (it's ugly) - but it's really useful for debugging.
Our friend the console and console.log
Puts a result in the console - use Chrome or Firebug (must be open)
Variables
Let's do some math and some string manipulation and write out to the console.
Functions
Created with the "function" keyword, create reusable pieces of functionality.
Scope
You can only use variables that are defined in the scope you call them.
Returning from Functions
Use the return keyword to pass a value back to whatever called the function
Timeouts
we can use setTimeout to have something happen later, try it
Anonymous functions, callbacks
We don't have to give our callback function a name, we can do it anonymously
Why callbacks?
A lot of stuff on the web happens "Asynchronously" - AJAX, user actions, etc
Arrays
-
Usually created with the bracket [ ] operator:
var arr = [ 10, 20, 30 ];
-
Pull out a value using square brackets [] starting at 0:
arr[0] // 10
arr[1] // 20
-
get the number of entries with .length
arr.length // 3
Playing with arrays
Objects
Objects
Conditionals
-
Things in javascript are either true or not true.
-
0, false, null, "" are all false
-
Everything else is true.
-
Use operands to check relationship between two values:
==, ===, <=, >=, !=
1 == 2 // false
1 == 1 // true
-
Basic conditionals:
Conditional Exercise
Use a conditional to check if a user confirmed a ok/cancel question. Then use prompt and test against a return value.
jQuery Basics
-
Everything is “namespaced” inside of the jQuery object, which is aliased with “$”
-
...which means everything you do in jQuery starts with a $
-
Uses CSS selectors for picking pieces of the DOM out.
Docs are your Friend
Loading jQuery
Include from a CDN or locally
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
Or
<script src='js/jquery.min.js'></script>
Need to make sure we have the file in the right location, can view in browser if there's a problem.
Using jQuery
Since we often include Javscript in the head of the document, we need to make sure we wait until the
page is loaded before we use it. We can use the jQuery bind function to load stuff at the appropriate point.
<script>
$(document).on("ready",function() {
// Dom Loaded
});
</script>
Why this is important..
Shorthand
Since this is so common, we can use a shorthand for this of $(function() { }) ...
<script>
$(function() {
// Dom Loaded
});
</script>
Basic selection + manipulation
Let's try out $.text, $.html, $.hide, $.show, $.css, $.attr, $.addClass, $.hasClass, $.removeClass
Selector Docs / Manipulation Docs
Some basic DOM insertion
Let's try out creating elements with $(), then using $.before, $.after, $.append, $.prepend, $.wrap, $.appendTo, both with text and elements.
Fun Stuff: Animation and transforms
$.fadeOut, $.fadeIn, $.slideDown, $.slideUp, $.toggle, $.stop, $.animate
Events
$.click, $.on, $.off, $.hover
Demo Revisited
The goal is to understand everything in here by the end of class today
Putting it all together
Let's use two buttons to increase and decrease a counter.
Plugins
Let's use the cycle plugin: http://jquery.malsup.com/cycle/ (images from http://lorempixel.com)
Ajax
$.ajax, $.get, $.post, $.getJSON
JSONp
Ajax is same-domain only. So there's a hack to pull data across domains called $.getScript
Project
-
Download Boilerplate
-
Download Bootstrap
-
Find a JavaScript API or two - perferably JSONp Programmable Web
-
Create a Mashup using Bootstrap to style