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

view-source:https://twitter.com

 view-source:https://twitter.com

A very brief overview of twitter.com's frontend architecture

Giuseppe Gurgone

January 25, 2017
Tweet

More Decks by Giuseppe Gurgone

Other Decks in Technology

Transcript

  1. @giuseppegurgone 2010 #!NewTwitter Fully Client Side Application jQuery, Mustache, LABjs,

    Modernizr Home grown MVC “Necessary complexity” – Dan Webb
  2. @giuseppegurgone @danwrong yey! The future is coming and it looks

    just like the past, but more good underneath. — Tom Lea (@cwninja) May 23, 2012 Server side rendering – 4x faster Progressive Enhancement Flight.js – Component based UI framework CommonJS + AMD via Loadrunner hashbang #! Hello PushState
  3. function inbox() { this.attributes({ myProp: 'hi' }) this.doSomething = function

    () { this.trigger(document, 'uiDoingSomething') /* ... */ } // after initializing the component this.after('initialize', function () { this.on('click', this.doSomething) }) } var Inbox = flight.component(inbox) /* Attach the component to a DOM node */ Inbox.attachTo('#inbox', { myProp: 'hello' }) Flight.js A component-based, event-driven JavaScript framework @giuseppegurgone
  4. Flight.js Components @giuseppegurgone Get a reference to a node this.$node

    Organised in UI and Data components Decoupled – trigger and subscribe to DOM events Isolated and easy to test and reason about
  5. var UiTimeline = require('components/ui/Timeline') var DataTimeline = require('components/data/Timeline') /* ...

    */ function init(initData) { /* Attach components to DOM nodes */ UiTimeline.attachTo('#timeline', initData.timeline) DataTimeline.attachTo('#timeline', initData.timeline) /* ... */ } module.exports = init Code Splitting Bundles @giuseppegurgone
  6. <input type="hidden" id="init-data" class="json-data" value="{ App data in JSON }">

    <input type="hidden" class="swift-boot-module" value="app/pages/permalink"> <input type="hidden" id="swift-module-path" value="https://abs.twimg.com/c/swift/en"> <script src="https://abs.twimg.com/k/en/init.en.38255812c7627517cc63.js" async> </script> App Initialization Bootstrapping @giuseppegurgone
  7. /* Grab initial data */ var initData = {} try

    { initData = $.parseJSON( $('#init-data').val() ) } catch (e) {} /* Grab modules base path */ var basePath = using.path = $('#swift-module-path').val() /* Grab modules names */ var modules = $('.swift-boot-module').map(function (_, module) { return module.val() }).toArray() /* require modules and call their exported function (init) with initData */ using(modules, function () { [].slice.call(arguments).forEach(function (init) { init(initData) }) }) App Initialization Bootstrapping @giuseppegurgone
  8. PushState via HTML5 History API Progressive Enhacement UI component to

    catch clicks on .js-nav links Data component to fetch data and update the URL / History UI component to update the UI Routing @giuseppegurgone