Cross platform web app development Tomás Pérez - @tomasperezv José M. Pérez - @jmperezperez
Slide 2
Cross platform application development
Contents Web development in Spotify - Why and how - Benefits and learnings Key web technologies that we use - IFrames and postMessage: security and performance - Communication between different tabs Summary Questions
Slide 3
Cross platform application development
Spotify <3 web
Slide 4
Cross platform application development
Beginnings of Spotify
Slide 5
Cross platform application development
Giving web a try
● Using CEF to move features to web ● Write features as webapps ● Sandboxed environment
Slide 6
Cross platform application development
Giving web a try (2)
Slide 7
Cross platform application development
What is a Spotify app?
● HTML ● CSS ● JS ● manifest.json
Slide 8
Cross platform application development
What is a Spotify app? - Developer tools
Slide 9
Cross platform application development
Architecture of the Spotify Apps Platform - overview
Slide 10
Cross platform application development
Architecture of the Spotify Apps Platform - desktop
Slide 11
Cross platform application development
Architecture of the Platform - all clients
Slide 12
Cross platform application development
Multiple platforms
CapturFiles_25.png
Slide 13
Cross platform application development
Releasing Spotify Apps
● Decoupled system ● Provides gradual roll-out, and availability depending on platform and country
Slide 14
Cross platform application development
Benefits ● Feature ownership by teams ● Fast development pace due to fewer dependencies ● Less hassle to deploy. Makes it easy to tweak a feature after being released ● 3rd party app development
Slide 15
Cross platform application development
Only benefits?
● Performance in views with a lot of data on mobile ● Time to render
Cross platform application development
Spotify Embedded Platform
Slide 18
Cross platform application development
Content Platform architecture - IFrames and postMessage: security and performance Remote control technology - Communication between different tabs - Performance of the communication channel Performance improvements
Slide 19
Cross platform application development
Architecture of the Platform
Slide 20
Cross platform application development
Sandboxed platform using IFrames Good - Separated execution context - Better security and privacy - We control the release process Bad - More difficult communication - IFrames are expensive
Slide 21
Cross platform application development
How expensive are IFrames?
A lot():
() http://www.stevesouders.com/blog/2009/06/03/using-iframes-sparingly/
Slide 22
Cross platform application development
Custom widgets in partner pages
Slide 23
Cross platform application development
Cross-origin communication using postMessage
Slide 24
Cross platform application development
Sending: content of the message frame.contentWindow.postMessage(message, ...); msg [in] Type: any One of the following: ● JavaScript primitive, such as a string ● object ● Array ● ...
(*)[object Object]
Slide 25
Cross platform application development
Security frame.contentWindow .postMessage(..., 'https://embed.spotify.com');
window.addEventListener('message', function(messageEvt) { if (messageEvt.origin === 'https://valid-domain.com') { ... } });
Slide 26
Cross platform application development
postMessage transfer rate
Slide 27
Cross platform application development
Remote controlling Spotify Clients Client Desktop: based on long polling + https Webplayer: communication with another browser window or tab - server side - postMessage - Cookies - localStorage
Slide 28
Cross platform application development
Is localStorage always available? window.localStorage localStorage.setItem('key', 'value') Storage DOMException constructor: StorageConstructor code: 22 length: 0 constructor: DOMExceptionConstructor message: "QUOTA_EXCEEDED_ERR: DOM Exception 22"
Slide 29
Cross platform application development
Communication between different tabs
Slide 30
Cross platform application development
localStorage locks The UI Thread is stopped for some operations Firefox and Chrome wait until the first read is requested, then load all the items
http://calendar.perfplanet.com/2012/is-localstorage-performance-a-problem/
Slide 31
Cross platform application development
localStorage notifications via the storage event window.addEventListener('storage', function() {}, false);
The event change is only emitted when the values actually change: use a timestamp if needed. {key: 'command', value: 'play', timestamp: 1373021690574}
Slide 32
Cross platform application development
Can we trigger the event manually? var evt = document.createEvent('StorageEvent'); evt.initStorageEvent('storage', ...); window.dispatchEvent(evt);
Yes...although not to communicate between different windows.
Slide 33
Cross platform application development
localStorage communication strategies Options: A) Create a new item every time, but remove it once it’s received. B) New item, don't remove once it’s received, instead do it regularly. C) Reuse always the same item (use timestamp)
Cross platform application development
Potential improvements Batching postMessages Webworkers
Slide 37
Cross platform application development
Conclusions - Web apps have been a good choice to extend our functionality in multiple platforms. - Web technologies make relatively easy to create complex integrations to improve the user experience. - It is very important to monitor and analyze carefully the performance.
Slide 38
Cross platform application development
Questions? Tomás Pérez @tomasperezv José M. Pérez @jmperezperez Slides, code examples and reference github.com/tomasperezv/spainjs-2013