The document discusses technologies for developing single-page applications (SPAs). It describes frameworks like Durandal and KnockoutJS that use patterns like MVVM and support features such as routing and real-time communication. It also covers languages and libraries that support SPAs including HTML5, CSS3, TypeScript, Underscore, Async, Bootstrap, Less, and the QUnit testing framework. Developing SPAs is more complex than traditional websites due to moving more logic to the client and refining technologies.
5. Single page application
SPA is a web application fitting on a single
web page with the goal of providing a more
fluid user experience akin to a desktop
application.
6. SPA - Features
• Chunking
• Controllers
• Templating
• Routing
• Real-time communication
• Local storage
• Testing
7. SPA - Chunking
The web server combines
HTML and data and sends
them to the client every time
it receives a request.
The web page is constructed
by loading chunks of HTML
fragments and data.
NoSPA SPA
8. SPA - Controllers
Scripting JavaScript:
• DOM management
• Data manipulation
• Application logic
• AJAX calls
Views and Models
separation thanks to MVC o
MVVM patterns:
• model → domain logic
• view → presentation logic
• controller → control logic
NoSPA SPA
9. SPA - Templating
UI and DOM manipulation by
using Javascript scripts.
There is declarative binding
of data to HTML templates
NoSPA SPA
10. SPA - Routing
Pages are reloaded at each
request.
Selection of views and
navigation (without page
reloads).
This preserves:
• Page state
• elements
• data
NoSPA SPA
11. SPA - Real-time communication
One-way request
communication between
browser and server.
Two-way communication of
a client application and web
server replaces one-way
requests from a browser.
NoSPA SPA
12. SPA - Local storage
• Intensive data loads only
on web server.
• Cookies use.
Capabilities of storing data
on a browser for
performance and offline
access replace cookies and
intensive data loads from
web server.
NoSPA SPA
13. SPA - Testing
“Trial and Error” testing
technique is used.
TDD and BDD approach are
adopted by using specific
testing frameworks.
NoSPA SPA
16. HTML5
HTML or HyperText Markup Language is the
standard markup language used to create web
pages.
HTML5 introduces new elements and attributes
for complex web applications.
17. HTML5 - What is new?
• New elements
• New attributes
• CSS3 support
• Video and Audio
• 2D/3D graphic support
• Local Storage
• Local SQL Database
• Web Applications
18. HTML5 - What is new?
Multimedia:
• Generic<object> tag is replaced by <video> and
<audio> specific tags.
Graphic:
•<canvas> tag is introduced
•Ability to use inline SVG
•CSS3 2D/3D support
19. HTML5 - What is new?
Applications:
• Local data storage
• Local file access
• Local SQL database
• Application cache
• Javascript workers
• XHTMLHttpRequest 2
• Geolocalization
20. HTML5 - What is new?
Semantic elements:
New elements are introduced: <header>, <footer>,
<menu>, <section> e <article>
Forms:
New elements, new attributes, new input type and
automatic validation.
21.
22. CSS3
Cascading Style Sheets (CSS) is a style sheet language
used for describing the look and formatting of a
document written in a markup language.
CSS3 is divided into several separate documents called
"modules". Each module adds new capabilities or
extends features defined in CSS 2, preserving backward
compatibility.
23. CSS3 - What is new?
• New selectors
• New properties
• Animations
• 2D/3D transformations
• Rounded corners
• Shading
• Downloadable fonts
24.
25. Durandal
Durandal is a lightweight JavaScript framework
designed to make building Single Page
Applications (SPAs) simple and elegant.
26. Durandal - Features
• MV* Architecture support
• JavaScript and HTML modularity
• Application Lifecycle
• Navigation
• asynchronous programming by using Promises
• Optimization
• Based on jQuery, Knockout and RequireJS
27.
28. KnockoutJS
Knockout is a JavaScript library that helps
you to create rich, responsive display and
editor user interfaces with a clean underlying
data model.
It implements MVVM patterns and allows
templates using.
29. KnockoutJS - Example
function ViewModel() {
this.firstName = ko.observable();
}
ko.applyBindings(new ViewModel());
<html>
<head>
<script type=”text/javascript”
src=”knockout-3.1.0.js”></script>
<script type=”text/javascript”
src=”myscript.js”></script>
</head>
<body>
<input data-bind=“value: firstName”>
My name is
<span data-bind=“text: firstName”></span>
</body>
</html>
myscript.js mypage.html
30. KnockoutJS - Example
function ViewModel() {
this.firstName = ko.observable();
this.lastName = ko.observable();
this.fullName=ko.computed(function() {
return this.firstName()+’ ‘+this.lastName();
});
}
ko.applyBindings(new ViewModel());
<html>
<head>
<script type=”text/javascript”
src=”knockout-3.1.0.js”></script>
<script type=”text/javascript”
src=”myscript.js”></script>
</head>
<body>
<input data-bind=“value: firstName”>
<input data-bind=“value: lastName”>
My name is
<span data-bind=“text: fullName”></span>
</body>
</html>
myscript.js mypage.html
33. TypeScript
TypeScript is a free and open source
programming language developed by Microsoft.
It is a strict superset of JavaScript, and adds
optional static typing and class-based object-
oriented programming to the language.
34. TypeScript - Example
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return ‘Hello, ‘ + this.greeting;
}
}
var greeter = new Greeter(‘world’);
var button = document.createElement(‘button’);
button.onclick = function() {
alert(greeter.greet());
}
document.body.appendChild(button);
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return ‘Hello, ‘ + this.greeting;
};
return Greeter;
})();
var greeter = new Greeter(‘world’);
var button = document.createElement(‘button’);
button.onclick = function () {
alert(greeter.greet());
};
document.body.appendChild(button);
myscript.ts myscript.js
35.
36. JS Utils - Underscore
Underscore is a JavaScript library that provides a whole
mess of useful functional programming helpers without
extending any built-in objects.
Thanks to it modern browsers can use the native
implementations of forEach, map, reduce, filter, every,
some and indexOf.
38. JS Utils - Async
Async is a utility module which provides
straight-forward, powerful functions for
working with asynchronous JavaScript.
39. JS Utils - Async - Example
async.series([
function(callback){
// do some stuff ...
callback(null, ’one’);
},
function(callback){
// do some more stuff …
callback(null, ’two’);
}
],
// optional callback
function(err, results){
// results is now equal to ['one', 'two']
});
async.parallel([
function(callback){
setTimeout(function(){
callback(null, ’one’);
}, 200);
},
function(callback){
setTimeout(function(){
callback(null, ’two’);
}, 100);
}
],
// optional callback
function(err, results){
// the results array will equal ['one','two’] even
// though second function had a shorter timeout.
});
40.
41. Bootstrap
Bootstrap is a free collection of tools for
creating websites and web applications.
It contains HTML and CSS-based design
templates for typography, forms, buttons,
navigation and other interface components, as
well as optional JavaScript extensions.
43. Less
Less (Leaner CSS) is a dynamic stylesheet
language that provides the following mechanisms
for CSS: variables, nesting, mixins, operators and
functions;
The indented syntax of LESS is a nested
metalanguage, as valid CSS is valid LESS code
with the same semantics.