SlideShare a Scribd company logo
Offline Mode
Web	Applications	for	Offline	Use
@pleckey	|	http://pleckey.me
Who is this guy?
Patrick	Leckey
Director	of	Engineering
In-Touch	Insight	Systems	Inc.
http://www.intouchinsight.com
Offline Mode - Web Applications Offline
Offline Mode - Web Applications Offline
Offline Mode - Web Applications Offline
Online is easy
Offline is ... easy?
But what if ...
Offline Mode - Web Applications Offline
Offline Mode - Web Applications Offline
Offline Mode - Web Applications Offline
Offline Mode - Web Applications Offline
... you're not guaranteed to
have connectivity the whole
way ...
What we have now ...
LocalStorage
window.localStorage
ApplicationCache
window.applicationCache
Chrome:	4+,	Firefox:	3.5+,	Safari:	4+
Mobile	Safari:	3.2+,	Android	Browser:	2.1+
IE:	10+
LocalStorage
simple
straightforward
rather	limited
ApplicationCache
complex
confusing
powerful
LocalStorage
...	it's	basically	a	shelf	...
Put	stuff	on	the	shelf
Take	stuff	off	the	shelf
Can	only	hold	so	much	stuff
LocalStorage
Similar	to	Cookies
...	but	not	transmitted	on	each	request
Send	what	you	want,	when	you	want!
LocalStorage
Key	/	Value	pairs
Limited	storage	size
Same	Origin	Policy!
http://pleckey.me	!=	https://www.pleckey.me
LocalStorage
5	MB	limit
As	JavaScript	strings	...
1.2345678
4	byte	float?		9	bytes	of	characters?
Nope!
18-byte	UTF-16	string
LocalStorage
window.localStorage.getItem(	'foo'	);	//	null
window.localStorage.setItem(	'foo',	'bar'	);
window.localStorage.getItem(	'foo'	);		//	"bar"
window.localStorage.length;	//	1
JSON.stringify(	window.localStorage	);	//	{"foo":	"bar"}
window.localStorage.removeItem(	'foo'	);	//	does	nothing	if	key	doesn't	exist
window.localStorage.clear();	//	remove	ALL	items
LocalStorage
What happens when the shelf is full?
try	{
				window.localStorage.setItem(	'foo',	really_big_thing	);
}	catch	(	e	/*	DOMException	*/	)	{	
				if	(	e.name	==	'QuotaExceededError'	)
								//	Chrome,	Safari,	IE
				else	if	(	e.name	==	'NS_ERROR_DOM_QUOTA_REACHED'	)
								//	Firefox
}
LocalStorage
Good	Ideas
application	state
user	information
	
Bad	Ideas
base64-encoded	images
postal	code	lookup	database
ApplicationCache
...	is	basically	a	...	uh	...	cache	...
Pre-cache	resources
Access	resources	offline
Fallback	to	alternates	for	dynamic	resources
ApplicationCache
No	storage	limit
Event-driven	API	
Cache	is	based	on	manifest	URL
ApplicationCache
	<html	manifest="/cache.manifest">
mime	type	must	be	text/cache-manifest
cache.manifest
CACHE
NETWORK
FALLBACK
cache.manifest
CACHE
CACHE	MANIFEST
#	Version:	8cf54be2
CACHE:
/favicon.png
/logo.png
/site/page2.html
explicitly	cached	resources
cache.manifest
NETWORK
CACHE	MANIFEST
#	Version:	8cf54be2
CACHE:
/favicon.png
...
NETWORK:
*
resources	that	require	the	user	to	be	online
usually	just	"*"
cache.manifest
FALLBACK
CACHE	MANIFEST
#	Version:	8cf54be2
CACHE:
/favicon.png
/static.html
NETWORK:
*
FALLBACK:
/dynamic.php	/static.html
resource	to	load	if	requested	resource	not	available	offline
ApplicationCache
cached	items	are	always	served	from	the	application	cache
the	application	cache	will	not	update	unless	the	cache
manifest	file	content	changes
ApplicationCache
CACHE	MANIFEST
#	Version:	8cf54be2
CACHE:
/script.js
NETWORK:
*
text	content	has	to	be	changed
Pretty Simple, right?
...	and	you	thought	it'd	be	that	easy	...
Oops #1
Non-cached	resources	don't	exist.
Even	when	you're	online.
NETWORK:
*
Oops #2
The	application	cache	works	with	the	browser	cache.
Sort	of.
Cache-Control:	max-age=9999999999
Oops #3
Caching	the	cache	manifest.
It'll	never	update.
Cache-Control:	no-cache,	no-store
Clearing the ApplicationCache
HTTP/1.0	410	Gone
ApplicationCache Events
window.applicationCache.addEventListener(	...	);
/**
	*	'checking'	-	browser	is	checking	for	an	update	(always	first)
	*
	*	'cached'	-	fired	after	first	download	of	a	new	cache	manifest
	*
	*	'downloading'	-	new	/	updated	resources	found,	browser	is	fetching
	*
	*	'error'	-	manifest	returned	404	or	a	download	failed
	*
	*	'noupdate'	-	cache	manifest	has	not	changed
	*
	*	'obsolete'	-	manifest	returned	410,	cache	deleted
	*
	*	'progress'	-	X	of	Y	manifest	resources	downloaded
	*
	*	'updateready'	-	all	updates	downloaded
	*/
ApplicationCache API
window.applicationCache.addEventListener(	'updateready',	function(	e	)	{
				alert(	'New	version	downloaded.		Application	will	now	reload.'	);
				window.location.reload();
}	);
window.applicationCache.update();
ApplicationCache API
window.applicationCache.addEventListener(	'updateready',	function(	e	)	{
				alert(	'New	version	downloaded.		Application	will	now	reload.'	);
				window.applicationCache.swapCache();
}	);
window.applicationCache.update();
Offline Mode - Web Applications Offline
iframe is your friend
<!--	iframe_js.html	-->
<html>
<script	type="application/javascript">
store	large	lookup	data	in	iframes
iframe is your friend
<!--	index.html	-->
<html	manifest="/cache.manifest">
<iframe	src="iframe_js.html"	width="0"	height="0"	border	="0"/>
</html>
CACHE	MANIFEST
#	Version:	1
CACHE:
/iframe_js.html
NETWORK:
*
include	lookup	data	in	cache	manifest
load	via	iframe	(same	origin)
iframe is your friend
//	index.html	console
>	window.awesome_data
			Object	{con:	"foo",	bar:	"baz"}
var	appCache	=	window.applicationCache;
if	(	appCache.status	!=	appCache.status.CACHED	)	{
				//	not	cached	yet,	do	an	AJAX	lookup
}	else	{
				return	window.awesome_data.con;	//	"foo"
}
Single Page Applications
pre-cache	static	resources	(speed!)
Native(ish) Web App
<meta	name="apple-mobile-web-app-capable"	content="yes"/>
<meta	name="mobile-web-app-capable"	content="yes"/>
runs	full	screen
built-in	software	updates
queue	data	for	submission	later
What Else Can I Do With This?
Come	work	for	us!
Software	Developer
User	Experience
Data	Scientist
Thank you!
Questions?
@pleckey	|	http://pleckey.com

More Related Content

ODP
Bruce Lawson HTML5 South By SouthWest presentation
ZIP
How I Learned to Stop Worrying and Love the Internet
PDF
Safer browsing
PPTX
Open edx developing x-blocks @ upvalencia (4)
PPTX
Web browser(16 03-2018)
PDF
Spirit-teknologiapäivät Petri Niemi HTML5 & JavaScript Developereille
PPTX
Web Browser ! Batra Computer Centre
PDF
WordCamp Minnepolis 2015: From Zero To WordPress Publish
Bruce Lawson HTML5 South By SouthWest presentation
How I Learned to Stop Worrying and Love the Internet
Safer browsing
Open edx developing x-blocks @ upvalencia (4)
Web browser(16 03-2018)
Spirit-teknologiapäivät Petri Niemi HTML5 & JavaScript Developereille
Web Browser ! Batra Computer Centre
WordCamp Minnepolis 2015: From Zero To WordPress Publish

Viewers also liked (11)

PPTX
ECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
PDF
Zepto and the rise of the JavaScript Micro-Frameworks
PDF
Javascript Framework Acessibiliity Review
PDF
Create a landing page
PDF
Metaprogramming JavaScript
PDF
Paweł Danielewski, Jak wygenerować 56% konwersji na Landing Page i 193.000 zł...
PDF
Creating responsive landing pages using LeadSquared
PDF
WebApps e Frameworks Javascript
PDF
50 Landing Page Best Practices
PDF
Unobtrusive JavaScript with jQuery
PDF
Writing Efficient JavaScript
ECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
Zepto and the rise of the JavaScript Micro-Frameworks
Javascript Framework Acessibiliity Review
Create a landing page
Metaprogramming JavaScript
Paweł Danielewski, Jak wygenerować 56% konwersji na Landing Page i 193.000 zł...
Creating responsive landing pages using LeadSquared
WebApps e Frameworks Javascript
50 Landing Page Best Practices
Unobtrusive JavaScript with jQuery
Writing Efficient JavaScript
Ad

Similar to Offline Mode - Web Applications Offline (20)

PDF
Offline first, the painless way
PDF
Offline browser testing
PPTX
HTML5 Local Storage
PDF
Lt local storage
PPTX
App cache vs localStorage
PDF
Creating Rajanikant Powered Site
PPTX
How to use local storage and session storage for offline functionalities in O...
PPT
HTML 5 Offline Web apps
PDF
Building great mobile apps: Somethings you might want to know
PDF
Offline Strategies for HTML5 Web Applications - oscon13
PPTX
HTML5 Web storage
PPTX
Offline Webapps
PDF
Offline for web - Frontend Dev Conf Minsk 2014
PDF
Offline of web applications
PDF
Web Storage
PPTX
Taking Web Applications Offline
PDF
Your browser, my storage
PDF
Html5 and beyond the next generation of mobile web applications - Touch Tou...
PPSX
JSinSa 2015 - Progressive Saving Using LocalStorage
PDF
An Overview of HTML5 Storage
Offline first, the painless way
Offline browser testing
HTML5 Local Storage
Lt local storage
App cache vs localStorage
Creating Rajanikant Powered Site
How to use local storage and session storage for offline functionalities in O...
HTML 5 Offline Web apps
Building great mobile apps: Somethings you might want to know
Offline Strategies for HTML5 Web Applications - oscon13
HTML5 Web storage
Offline Webapps
Offline for web - Frontend Dev Conf Minsk 2014
Offline of web applications
Web Storage
Taking Web Applications Offline
Your browser, my storage
Html5 and beyond the next generation of mobile web applications - Touch Tou...
JSinSa 2015 - Progressive Saving Using LocalStorage
An Overview of HTML5 Storage
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
A Presentation on Artificial Intelligence
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25-Week II
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Building Integrated photovoltaic BIPV_UPV.pdf
Big Data Technologies - Introduction.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Dropbox Q2 2025 Financial Results & Investor Presentation
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
A Presentation on Artificial Intelligence
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology

Offline Mode - Web Applications Offline