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

Beyond The Tab: Executing JavaScript Across Browser Contexts @ Abstractions

Beyond The Tab: Executing JavaScript Across Browser Contexts @ Abstractions

Keeping JavaScript from interfering across tabs is great and all, but what about when a web application wants to share state without involving a server? This talk will cover both older as well as emerging web standards to share JavaScript context — between tabs directly and through background threads that are natively supported by browsers (SharedWorker and ServiceWorker). You’ll leave with enough knowledge to get started and enough wisdom to know when to use these tools.

Andrew Dunkman

August 19, 2016
Tweet

More Decks by Andrew Dunkman

Other Decks in Technology

Transcript

  1. var cookieSearchRegex = new RegExp( "(?:(?:^|.*;)\\s*" + cookieName + "\\s*\\=\\s*([^;]*).*$)|^.*$");

    return decodeURIComponent( document.cookie.replace( cookieSearchRegex, "$1"));
  2. var clients = []; self.addEventListener("connect", function (event) { var port

    = event.ports[0]; clients.push(port); port.addEventListener("message", function (event) { broadcast(event.data); } ); port.start(); } );
  3. The implementation of Shared Web Workers was imposing undesirable constraints

    on the engine. The feature never gained any adoption and was eventually removed from the engine.
  4. var broadcast = function (message) { self.clients.matchAll().then( function (clients) {

    clients.forEach( function (client) { client.postMessage(message); } ); } ); };