Upload
ket-majmudar
View
92
Download
0
Embed Size (px)
DESCRIPTION
London Titanium talk on compressing JSON responses
Citation preview
JSONHAn story in mobile API optimisation & how to get data
stuff faster.
Tuesday, 1 April 14
Tuesday, 1 April 14
Back in the day when I could barely pronounce API and for me, JavaScript was some esoteric magic that induced pain and wonder.
Tuesday, 1 April 14
Mobile phones were unwieldy bricks of plastic and metal with huge antennas and then hefty charge
W.A.P was the new kid on the block and I had to print out yet another manual to accompany my hefty collection of mySQL 3.x and HTML / HTTP specs
I can remember that it filled me with hope & excitement period and helped cross the bridge between our flashy web bracket plan intended bracket and these always connected devices with screens the size of stamps
Tuesday, 1 April 14
Actually taking to where what's the point of this well today, you see, we have a super bit, quadruple powered Infinity Gauntlet charged broadband speeds...
It's made us a little lazy KiloBytes?... pah! Peanuts four our broadband connected society…
Tuesday, 1 April 14
But then came the iPhone followed by nestle droid sorry android and the rabbit holes appeared we developers dived in red pill please and our complacency led us to grow home bellies
Not really but my point is this to be really care or understand how user base not only in the first I know we do so how can we improve our code designs technical debt and get out of a lazy programming interface frame of mind
Cost of an API call
Tuesday, 1 April 14
I was looking for only that I wanted to increase performance speed reducing packet size & cost of an API call. Specifically for a mobile project talking to a node.ACS service interacting with one or more APIs
Mobile API query
TELCO WIFI
MIDDLEWARE SERVER
DATA BACKBONE
API PROVIDER DATA SOURCE
Cost of an HTTP
REQUEST...
Tuesday, 1 April 14
EXPLAIN DIAGRAM & MULTIPLE REQUESTS
JSONHJSON compression search
CJSON & JSON w HPack (now JSONH)
JSONH for Homogenous Collections
http://web-resource-optimization.blogspot.co.uk/2011/06/json-compression-algorithms.html
A collection of objects with the same dynamic type. Arrays are the most common homogeneous collection objects.
David J. Barnes
Tuesday, 1 April 14
Compression Comparison
JSONH looked best.
Tuesday, 1 April 14
Setting Up - 1
GET JSONH library
GET JSONminify (optional to strip whitespace/comments)
Add both libraries into your project.
Add to Node.ACS & into your Ti project
Tuesday, 1 April 14
Setting Up - 2Include the libs into your Node.ACS/Ti App / Server
Minify & pack the data
Return string
var jsonminify = require("jsonminify");var JSONH = require('jsonh');
! ! var resString = _minifyJS(data);! ! resString.Contents = JSONH.pack(resString.Contents);
! ! return (JSON.stringify(resString));
Tuesday, 1 April 14
Setting Up - 3decompress collection in app
! function callback(e) {! ! Ti.API.log('mobile request callback');! ! var rJson = JSON.parse(e);! ! // get return data and parse then unpack the JSON.! ! rJson.Contents = JSONH.unpack(rJson.Contents);! ! return rJson;! }
Tuesday, 1 April 14
ACS/AWS
3rd Party Service API Method
Stringify Reponse
Minify Reponse
pack JSONH homogenous
collection node
Mobile Function requires Data/ API
Call
Q
Q
Q
Parse responseText if required
UNPACK JSONH homogenous
collection node
API: XHR callback
API: XHR HTTPRequest
Node.ACS
Service API Method
JSON
D
Q Decision based on query parameters
D Data response from HTTPClient
API: callback
API: HTTPRequest
JSON / (string/min)ified
D
Mobile
JSON Compression: HPACK using jsonh.js Mobile > Node.ACS > ACS > Mobile
Ketan Majmudar
Tuesday, 1 April 14