SlideShare a Scribd company logo
1 of 37
Download to read offline
Persistent Mobile JS 
Tips & Tricks 
Yorick Phoenix / ISSIO Solutions, Inc 
slides: slidesha.re/1zdXBk6 
about.me/yorickphoenix | @scribblings | github.com/yphoenix | yorick@issio.net
Achieving Persistence 
1. Downloading to a 
mobile device. 
2. Keeping it cached. 
3. Timely updating.
Mobile Browser Issues 
Slow networking speeds.
Mobile Browser Issues 
Bad latency problems.
Mobile Browser Issues 
Code & data not (always) persistent across 
browser reloads. 
Causes re-downloads from your web server.
Mobile Browser Issues 
HTTP/1.1 200 OK 
Date: Fri, 03 Oct 2014 07:08:21 GMT 
Last-Modified: Fri, 26 Sep 2014 02:13:19 GMT 
Cache-Control: max-age=43200 
Expires: Fri, 03 Oct 2014 19:08:21 GMT 
Content-Encoding: gzip 
Content-Length: 622 
Content-Type: application/x-javascript 
Cache / Freshness tradeoff.
Easy #1 Solution… 
•Use PhoneGap / Cordova. 
Wrap your code in an app. 
•Download once. 
•Code & data are always 
available.
Easy #1 Solution Flaws 
•Multiple builds: iOS, Android, 
etc. 
•iOS WebView doesn’t use JIT. 
•Android WebView !== Chrome. 
•Different from Desktop version.
Easy #1 More Flaws 
•Slow app store updates. 
•Users don’t always update. 
•Sometimes never.
new Better(Solution); 
{ nativeBrowser: true, 
downloadSpeed: “fast”, 
deviceCaching: “best”, 
updates: “immediate”, 
workOffline: true }
Browser Debugging Tools 
• Learn how to use them. 
• Watch Network Traffic. 
• Track caching & compression. 
• Request and Response headers. 
• How to inspect resources & the DOM. 
• The console is your friend.
downloadSpeed: “fast” 
Minimize your files: 
!function(a,b){“object”==typeof module&&”object" 
==typeof module.exports?module.exports=a.document?b(a,! 
0):function(a){if(!a.document)throw new Error( "jQuery 
requires a window with a document");return b(a)}:b(a)} 
("undefined"!=typeof window?window:this, function(a,b) 
{var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf, 
h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m 
="2.1.1",n=function(a,b){return new n.fn.init(a,b)},o=/ 
^[suFEFFxA0]+|[suFEFFxA0]+$/g,p=/^-ms-/,q=/-([da-z])/ 
gi,r= function(a,b){return throw new a.indexOf(“use 
http://gpbmike.github.io/refresh-sf/ 
https://github.com/mishoo/UglifyJS
downloadSpeed: “fast” 
gzip your downloads: 
<ifModule mod_gzip.c> 
mod_gzip_on Yes 
mod_gzip_dechunk Yes 
mod_gzip_item_include file .(html|js|css)$ 
</ifModule> 
http://www.feedthebot.com/pagespeed/enable-compression. 
html
downloadSpeed: “fast” 
Cache your data & code as close 
to the user as you possibly can….
downloadSpeed: “fast” 
Use a good CDN and all this 
will be handled for you…
Use a CDN 
• Automatic minimization (js, css, html) 
• Automatic compression. 
• Automatic caching at a data center 
nearest your user. 
• Automatic redundancy of servers. 
• Basic level of service is FREE!
deviceCaching: “best” 
1. Browser cache. 
2. LocalStorage. 
3. App Cache 
(aka: Manifests)
1. Browser Cache 
• Cache your code, css, images. 
• Updates are automatic’ish. 
• Slow last modified checks with 
mobile latency + once per file.
Browser Cache Tradeoff 
• Calculate: Code Update Frequency 
• Because: Once in the users 
browser isn’t going to be updated 
without the user forcing it or 
expiration.
Browser Cache Issues 
• Trade off: cache expiration vs 
download frequency. 
• Need frequent updates: make it 
small. 
• Result: more frequent downloads or 
last modified checks. 
• Rule: You will always download 
more often than you really need to.
Browser Cache Updates 
• Unpredictable behavior. 
• Browser makes the decisions. 
• Don’t play the rename the file to 
update game.
window.location.reload() 
Don’t use reload to refresh 
window.location.reload(); 
last modified check for every reference 
Instead set the href to yourself 
window.location.href = 
window.location.pathname+ 
window.location.search; 
Unless you want to force a reload :-)
2. localStorage 
Can store code 
localStorage.myCode =  
‘function HelloWorld()  
{  
alert(“Hello, World”);  
}’; 
Can store data 
localStorage.myData =  
‘{Days: [“Sun”, “Mon”, “Tue”, “Wed”,  
“Thu”, “Fri”, “Sat”],  
Months: [31, 28, 31, 30, 31, 30,  
31, 31, 30, 31, 30, 31]}’;
localStorage 
• Store any arbitrary string. 
• On a domain by domain basis. 
• Updates under your own control.
localStorage 
• Persistent between browser launches: 
• JSON 
• CSS 
• JavaScript 
• 5MB Limit: who writes 5M of 
minimized code or data?
updates: localStorage 
• You store and update only when 
you want to. 
• Best for code/css and static data, 
not for images.
Store JS in localStorage 
$('script[src]').map( 
function(idx, val) { 
var url, name; 
url = $(val).attr('src'); 
name = url.replace(/[^a-zA-Z]/g,'-'); 
while (name[0] === ‘-') { 
name = name.slice(1); 
} 
$.get(url, 
function (code) { 
localStorage[name] = code; 
}); 
});
3. AppCache (Manifest) 
• Store any resource: 
• JavaScript 
• CSS 
• Images 
• HTML 
• Any file you like…
AppCache 
• Single “last modified” check 
updates lots of files. 
• Automatic fallback to the network. 
• Can work totally offline.
AppCache 
<html manifest="cache.manifest"> 
CACHE MANIFEST 
NETWORK: 
* 
CACHE: 
/favicon.ico 
/index.html 
/js/lib/jquery.min.js 
/js/lib/mylibs.js 
/css/mainStyles.css 
//ajax.googleapis.com/ajax/libs/jquery/2.1.1/ 
jquery.min.js 
... 
You store any file you want…
AppCache Update Control 
• You - sort of - control this one. 
• Can have different behaviors on 
different pages. 
• You store and update only when you 
want to. 
% touch cache.manifest 
• Also programatic control & events.
AppCache References 
• www.html5rocks.com/en/tutorials/ 
appcache/beginner/ 
• alistapart.com/article/application-cache- 
is-a-douchebag 
• www.whatwg.org/specs/web-apps/ 
current-work/multipage/ 
browsers.html#appcache
AppCache HTML5 Session 
References 
See Jeff Burtofts HTML 5 Session: 
Behold the power of the 
“Web App Manifest” 
Room E-133 @ 2:30pm on 10/20/14
Putting it all together 
• CDN for quick access. 
• localStorage for static data / code /css. 
• sessionStorage for run-time data 
(instead of server sessions). 
• app cache for every type of file.
workOffline: “true” 
• With localStorage, sessionStorage & app 
cache (manifests). 
• This is a reality. 
• Plus: whenever there is a network 
connection you can get new content, 
resources and code. 
• eg: Google Homepage 
(~250KB of App cache)
updates: “immediate” 
• You should be in control your updates. 
• Browser cache - hit and miss. 
• LocalStorage - under your control. 
• App Cache - mixed bag.
Thank You 
Q &A 
Yorick Phoenix / ISSIO Solutions, Inc 
slides: slidesha.re/1zdXBk6 
about.me/yorickphoenix | @scribblings | github.com/yphoenix | yorick@issio.net

More Related Content

What's hot

JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresRobert Nyman
 
ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and ScaleITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and ScaleIstanbul Tech Talks
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppetAlan Parkinson
 
Будь первым
Будь первымБудь первым
Будь первымFDConf
 
Google App Engine Developer - Day4
Google App Engine Developer - Day4Google App Engine Developer - Day4
Google App Engine Developer - Day4Simon Su
 
Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)Joe Casabona
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsRemy Sharp
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer Hiroshi SHIBATA
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by expressShawn Meng
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHPWim Godden
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challengervanphp
 
Responsive Design with WordPress
Responsive Design with WordPressResponsive Design with WordPress
Responsive Design with WordPressJoe Casabona
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopJachym Cepicky
 
Angular&node js upload file
Angular&node js upload fileAngular&node js upload file
Angular&node js upload fileHu Kenneth
 
MeshU Thin & Rack
MeshU Thin & RackMeshU Thin & Rack
MeshU Thin & Rackguestbac5dc
 
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
WorkFlow:  An Inquiry Into Productivity by Timothy BoltonWorkFlow:  An Inquiry Into Productivity by Timothy Bolton
WorkFlow: An Inquiry Into Productivity by Timothy BoltonMiva
 

What's hot (20)

JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
 
ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and ScaleITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppet
 
Будь первым
Будь первымБудь первым
Будь первым
 
Knex Postgresql Migration
Knex Postgresql MigrationKnex Postgresql Migration
Knex Postgresql Migration
 
Google App Engine Developer - Day4
Google App Engine Developer - Day4Google App Engine Developer - Day4
Google App Engine Developer - Day4
 
Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
Responsive Design with WordPress
Responsive Design with WordPressResponsive Design with WordPress
Responsive Design with WordPress
 
Node.js
Node.jsNode.js
Node.js
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS Workshop
 
Angular&node js upload file
Angular&node js upload fileAngular&node js upload file
Angular&node js upload file
 
Node.js
Node.jsNode.js
Node.js
 
MeshU Thin & Rack
MeshU Thin & RackMeshU Thin & Rack
MeshU Thin & Rack
 
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
WorkFlow:  An Inquiry Into Productivity by Timothy BoltonWorkFlow:  An Inquiry Into Productivity by Timothy Bolton
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
 

Similar to Persistent mobile JavaScript

Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"Binary Studio
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?Remy Sharp
 
Html5 : stockage local & synchronisation
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisationgoldoraf
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for youSimon Willison
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
 
把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡Wei Jen Lu
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patternsStoyan Stefanov
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
HTML5 on Mobile
HTML5 on MobileHTML5 on Mobile
HTML5 on MobileAdam Lu
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Web Directions
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gearsdion
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Arun Gupta
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Arun Gupta
 
Offline Application Cache
Offline Application CacheOffline Application Cache
Offline Application CacheJonathan Stark
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineRicardo Silva
 

Similar to Persistent mobile JavaScript (20)

Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
Cache is King
Cache is KingCache is King
Cache is King
 
Html5 : stockage local & synchronisation
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisation
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
HTML5 on Mobile
HTML5 on MobileHTML5 on Mobile
HTML5 on Mobile
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
React native
React nativeReact native
React native
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
 
Offline Application Cache
Offline Application CacheOffline Application Cache
Offline Application Cache
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 

Recently uploaded

Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNeo4j
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxNeo4j
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...drm1699
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jNeo4j
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio, Inc.
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfkalichargn70th171
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksJinanKordab
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanNeo4j
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfSrushith Repakula
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConNatan Silnitsky
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationElement34
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringPrakhyath Rai
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Conceptsthomashtkim
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Lisi Hocke
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...Neo4j
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIInflectra
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024MulesoftMunichMeetup
 

Recently uploaded (20)

Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 

Persistent mobile JavaScript

  • 1. Persistent Mobile JS Tips & Tricks Yorick Phoenix / ISSIO Solutions, Inc slides: slidesha.re/1zdXBk6 about.me/yorickphoenix | @scribblings | github.com/yphoenix | yorick@issio.net
  • 2. Achieving Persistence 1. Downloading to a mobile device. 2. Keeping it cached. 3. Timely updating.
  • 3. Mobile Browser Issues Slow networking speeds.
  • 4. Mobile Browser Issues Bad latency problems.
  • 5. Mobile Browser Issues Code & data not (always) persistent across browser reloads. Causes re-downloads from your web server.
  • 6. Mobile Browser Issues HTTP/1.1 200 OK Date: Fri, 03 Oct 2014 07:08:21 GMT Last-Modified: Fri, 26 Sep 2014 02:13:19 GMT Cache-Control: max-age=43200 Expires: Fri, 03 Oct 2014 19:08:21 GMT Content-Encoding: gzip Content-Length: 622 Content-Type: application/x-javascript Cache / Freshness tradeoff.
  • 7. Easy #1 Solution… •Use PhoneGap / Cordova. Wrap your code in an app. •Download once. •Code & data are always available.
  • 8. Easy #1 Solution Flaws •Multiple builds: iOS, Android, etc. •iOS WebView doesn’t use JIT. •Android WebView !== Chrome. •Different from Desktop version.
  • 9. Easy #1 More Flaws •Slow app store updates. •Users don’t always update. •Sometimes never.
  • 10. new Better(Solution); { nativeBrowser: true, downloadSpeed: “fast”, deviceCaching: “best”, updates: “immediate”, workOffline: true }
  • 11. Browser Debugging Tools • Learn how to use them. • Watch Network Traffic. • Track caching & compression. • Request and Response headers. • How to inspect resources & the DOM. • The console is your friend.
  • 12. downloadSpeed: “fast” Minimize your files: !function(a,b){“object”==typeof module&&”object" ==typeof module.exports?module.exports=a.document?b(a,! 0):function(a){if(!a.document)throw new Error( "jQuery requires a window with a document");return b(a)}:b(a)} ("undefined"!=typeof window?window:this, function(a,b) {var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf, h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m ="2.1.1",n=function(a,b){return new n.fn.init(a,b)},o=/ ^[suFEFFxA0]+|[suFEFFxA0]+$/g,p=/^-ms-/,q=/-([da-z])/ gi,r= function(a,b){return throw new a.indexOf(“use http://gpbmike.github.io/refresh-sf/ https://github.com/mishoo/UglifyJS
  • 13. downloadSpeed: “fast” gzip your downloads: <ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html|js|css)$ </ifModule> http://www.feedthebot.com/pagespeed/enable-compression. html
  • 14. downloadSpeed: “fast” Cache your data & code as close to the user as you possibly can….
  • 15. downloadSpeed: “fast” Use a good CDN and all this will be handled for you…
  • 16. Use a CDN • Automatic minimization (js, css, html) • Automatic compression. • Automatic caching at a data center nearest your user. • Automatic redundancy of servers. • Basic level of service is FREE!
  • 17. deviceCaching: “best” 1. Browser cache. 2. LocalStorage. 3. App Cache (aka: Manifests)
  • 18. 1. Browser Cache • Cache your code, css, images. • Updates are automatic’ish. • Slow last modified checks with mobile latency + once per file.
  • 19. Browser Cache Tradeoff • Calculate: Code Update Frequency • Because: Once in the users browser isn’t going to be updated without the user forcing it or expiration.
  • 20. Browser Cache Issues • Trade off: cache expiration vs download frequency. • Need frequent updates: make it small. • Result: more frequent downloads or last modified checks. • Rule: You will always download more often than you really need to.
  • 21. Browser Cache Updates • Unpredictable behavior. • Browser makes the decisions. • Don’t play the rename the file to update game.
  • 22. window.location.reload() Don’t use reload to refresh window.location.reload(); last modified check for every reference Instead set the href to yourself window.location.href = window.location.pathname+ window.location.search; Unless you want to force a reload :-)
  • 23. 2. localStorage Can store code localStorage.myCode = ‘function HelloWorld() { alert(“Hello, World”); }’; Can store data localStorage.myData = ‘{Days: [“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”], Months: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]}’;
  • 24. localStorage • Store any arbitrary string. • On a domain by domain basis. • Updates under your own control.
  • 25. localStorage • Persistent between browser launches: • JSON • CSS • JavaScript • 5MB Limit: who writes 5M of minimized code or data?
  • 26. updates: localStorage • You store and update only when you want to. • Best for code/css and static data, not for images.
  • 27. Store JS in localStorage $('script[src]').map( function(idx, val) { var url, name; url = $(val).attr('src'); name = url.replace(/[^a-zA-Z]/g,'-'); while (name[0] === ‘-') { name = name.slice(1); } $.get(url, function (code) { localStorage[name] = code; }); });
  • 28. 3. AppCache (Manifest) • Store any resource: • JavaScript • CSS • Images • HTML • Any file you like…
  • 29. AppCache • Single “last modified” check updates lots of files. • Automatic fallback to the network. • Can work totally offline.
  • 30. AppCache <html manifest="cache.manifest"> CACHE MANIFEST NETWORK: * CACHE: /favicon.ico /index.html /js/lib/jquery.min.js /js/lib/mylibs.js /css/mainStyles.css //ajax.googleapis.com/ajax/libs/jquery/2.1.1/ jquery.min.js ... You store any file you want…
  • 31. AppCache Update Control • You - sort of - control this one. • Can have different behaviors on different pages. • You store and update only when you want to. % touch cache.manifest • Also programatic control & events.
  • 32. AppCache References • www.html5rocks.com/en/tutorials/ appcache/beginner/ • alistapart.com/article/application-cache- is-a-douchebag • www.whatwg.org/specs/web-apps/ current-work/multipage/ browsers.html#appcache
  • 33. AppCache HTML5 Session References See Jeff Burtofts HTML 5 Session: Behold the power of the “Web App Manifest” Room E-133 @ 2:30pm on 10/20/14
  • 34. Putting it all together • CDN for quick access. • localStorage for static data / code /css. • sessionStorage for run-time data (instead of server sessions). • app cache for every type of file.
  • 35. workOffline: “true” • With localStorage, sessionStorage & app cache (manifests). • This is a reality. • Plus: whenever there is a network connection you can get new content, resources and code. • eg: Google Homepage (~250KB of App cache)
  • 36. updates: “immediate” • You should be in control your updates. • Browser cache - hit and miss. • LocalStorage - under your control. • App Cache - mixed bag.
  • 37. Thank You Q &A Yorick Phoenix / ISSIO Solutions, Inc slides: slidesha.re/1zdXBk6 about.me/yorickphoenix | @scribblings | github.com/yphoenix | yorick@issio.net