Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cross platform web development

Cross platform web development

This talk presents how Spotify uses web technologies to develop and maintain key features in the different platforms that compose the Spotify experience: desktop client, mobile apps and the Web Player.

Hybrid apps is a hot topic nowadays, and we explain how our architecture abstracts a web developer from the platform, making it possible to share code across multiple devices.

In addition, we talk about how we communicate with the Spotify clients, using web technologies such as localStorage to sync between different tabs and postMessages to achieve cross domain communication. We will also analyze some browser inconsistencies and will show work-arounds to solve them.

José M. Pérez

July 05, 2013

More Decks by José M. Pérez

Other Decks in Technology


  1. Contents Cross platform application development 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
  2. Giving web a try Cross platform application development • Using

    CEF to move features to web • Write features as webapps • Sandboxed environment
  3. Releasing Spotify Apps • Decoupled system • Provides gradual roll-out,

    and availability depending on platform and country Cross platform application development
  4. Benefits Cross platform application development • 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
  5. Content Cross platform application development Platform architecture - IFrames and

    postMessage: security and performance Remote control technology - Communication between different tabs - Performance of the communication channel Performance improvements
  6. Sandboxed platform using IFrames Cross platform application development Good -

    Separated execution context - Better security and privacy - We control the release process Bad - More difficult communication - IFrames are expensive
  7. 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 •...
  8. Remote controlling Spotify Clients Cross platform application development Client Desktop:

    based on long polling + https Webplayer: communication with another browser window or tab - server side - postMessage - Cookies - localStorage
  9. Is localStorage always available? Cross platform application development localStorage.setItem('key', 'value')

    DOMException code: 22 constructor: DOMExceptionConstructor message: "QUOTA_EXCEEDED_ERR: DOM Exception 22"
  10. localStorage locks Cross platform application development The UI Thread is

    stopped for some operations Firefox and Chrome wait until the first read is requested, then load all the items
  11. localStorage notifications via the storage event Cross platform application development

    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}
  12. Can we trigger the event manually? Cross platform application development

    Yes... although not to communicate between different windows. var evt = document.createEvent('StorageEvent'); evt.initStorageEvent('storage', ...); window.dispatchEvent(evt);
  13. localStorage communication strategies Cross platform application development 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)
  14. Performance improvements Cross platform application development Prefetch / Prerender •

    Rendering pages <link rel="prerender" href="..."> • Fetching static resources <link rel="prefetch" href="...">
  15. Conclusions Cross platform application development - 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.
  16. Questions? Cross platform application development Tomás Pérez @tomasperezv José M.

    Pérez @jmperezperez Slides, code examples and reference github.com/tomasperezv/spainjs-2013