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

Single-Page Applications: Challenges

Minko Gechev
September 12, 2015

Single-Page Applications: Challenges

Challenges in the front-end application development.

This slides discuss scalability and performance in the modern single-page applications.

Minko Gechev

September 12, 2015
Tweet

More Decks by Minko Gechev

Other Decks in Programming

Transcript

  1. Minko Gechev github.com/mgechev twitter.com/mgechev { "job": "Freelancer", "hobbies": [ "open

    source", "blogging", "teaching", "sports" ], "communityEvents": [ "SofiaJS", "BeerJS Sofia" ] }
  2. Agenda • Title 1 • Subtitle 1 • Subtitle 2

    • Title 2 • Subtitle 1 Lets take a look back…
  3. jQuery jQuery(function ($) { var popup = function () {

    if ($('.popup_close').length > 0) { $('.popup_close').on('click', function () { $(this).closest('.wrapper_outer_popup').addClass('hidden'); }); $('.popup_target').on('click', function () { $('.popup[data-popup="' + $(this).attr('data-target') + '"]').removeClass('hidden'); }); } }(popup); }(jQuery));
  4. jQuery spaghetti jQuery(function ($) { var popup = function ()

    { if ($('.popup_close').length > 0) { $('.popup_close').on('click', function () { $(this).closest('.wrapper_outer_popup').addClass('hidden'); }); $('.popup_target').on('click', function () { $('.popup[data-popup="' + $(this).attr('data-target') + '"]').removeClass('hidden'); }); } }(popup); $(document).on('ready', function () { $('.sisea-results-list').each(function () { var elements = $(this).find('.sisea-result'), size = elements.size(), find = 10; for (var i = 0; i < find; i++) elements.eq(i).show(300); $(window).on('scroll', function() { var scrollTop = window.pageYOffset || document.documentElement.scrollTop, offset = $('#scroll').offset().top; if (scrollTop > offset - 800) { find < size ? find += 10 : find = size; for (var i = 0; i < find; i++) elements.eq(i).show(300); } }); }); }); }(jQuery));
  5. jQuery spaghetti jQuery(function ($) { var popup = function ()

    { if ($('.popup_close').length > 0) { $('.popup_close').on('click', function () { $(this).closest('.wrapper_outer_popup').addClass('hidden'); }); $('.popup_target').on('click', function () { $('.popup[data-popup="' + $(this).attr('data-target') + '"]').removeClass('hidden'); }); } }(popup); $(document).on('ready', function () { $('.sisea-results-list').each(function () { var elements = $(this).find('.sisea-result'), size = elements.size(), find = 10; for (var i = 0; i < find; i++) elements.eq(i).show(300); $(window).on('scroll', function() { var scrollTop = window.pageYOffset || document.documentElement.scrollTop, offset = $('#scroll').offset().top; if (scrollTop > offset - 800) { find < size ? find += 10 : find = size; for (var i = 0; i < find; i++) elements.eq(i).show(300); } }); }); }); var popup_show_delay = 0.5; $('.in_basket').each(function(){ var $popup = $(this).find('.flyout'); var timeoutId = null; var showPopup = function() { $popup.removeClass('hidden'); }; var hidePopup = function() { $popup.addClass('hidden'); console.log('hide popup'); }; var $targets = $([ this, $popup.get(0) ]); $targets.on('mouseenter', function(){ console.log('show popup'); clearTimeout(timeoutId); showPopup(); }); $targets.on('mouseleave', function(){ clearTimeout(timeoutId); timeoutId = setTimeout(hidePopup, popup_show_delay * 1000); }); }); $(".doc_4").hover(function(){ $(".Kiril").css("display","block"); $(".beckzhan").css("display","none"); $(".Sergey").css("display","none"); $(".Asiya").css("display","none"); }); $(".doc_1").hover(function(){ $(".beckzhan").css("display","block"); $(".Kiril").css("display","none"); $(".Sergey").css("display","none"); $(".Asiya").css("display","none"); }); $(".doc_2").hover(function(){ $(".Sergey").css("display","block"); $(".beckzhan").css("display","none"); $(".Kiril").css("display","none"); $(".Asiya").css("display","none"); }); $(".doc_3").hover(function(){ $(".Asiya").css("display","block"); $(".beckzhan").css("display","none"); $(".Sergey").css("display","none"); $(".Kiril").css("display","none"); }); }(jQuery));
  6. architecture |ˈɑːkɪtɛktʃəә| noun [ mass noun ] 1 the art

    or practice of designing and constructing buildings. schools of architecture and design. • the style in which a building is designed and constructed, especially with regard to a specific period, place, or culture: Georgian architecture. 2 the complex or carefully designed structure of something: the chemical architecture of the human brain. • the conceptual structure and logical organization of a computer or computer-based system.
  7. A few MV* frameworks Backbone.js Flight KnockoutJS Knockback.js AngularJS Ember.js

    React MarionetteJS CanJS Vue.js Ampersand Mithril Aurelia Kendo UI PureMVC
  8. A few MV* frameworks Backbone.js Flight KnockoutJS Knockback.js AngularJS Ember.js

    React MarionetteJS CanJS Vue.js Ampersand Mithril Aurelia Kendo UI PureMVC
  9. A few MV* frameworks Backbone.js Flight KnockoutJS Knockback.js AngularJS Ember.js

    React MarionetteJS CanJS Vue.js Ampersand Mithril Aurelia Kendo UI PureMVC
  10. A few MV* frameworks Backbone.js Flight KnockoutJS Knockback.js AngularJS Ember.js

    React MarionetteJS CanJS Vue.js Ampersand Mithril Aurelia Kendo UI PureMVC
  11. A few MV* frameworks Backbone.js Flight KnockoutJS Knockback.js AngularJS Ember.js

    React MarionetteJS CanJS Vue.js Ampersand Mithril Aurelia Kendo UI PureMVC
  12. A few MV* frameworks Backbone.js Flight KnockoutJS Knockback.js AngularJS Ember.js

    React MarionetteJS CanJS Vue.js Ampersand Mithril Aurelia Kendo UI PureMVC
  13. – Wikipedia “Model–view–controller (MVC) is a software architectural pattern for

    implementing user interfaces.” Model–view–controller
  14. – Wikipedia “The observer pattern is a software design pattern

    in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their method.” Observer Pattern
  15. this.name  =  name;   $(‘#badge  .name’)      .html(name);  

    foreach  u  in  users  {      u.send({
        type:  ‘change’,
        name:  name      });   }
  16. Flux does: • Enforces the uni-directional data-flow • No more

    cascading updates and hidden dependencies • Keeps the UI as stateless as possible • No more troubles to reason about the state
  17. Agenda • Title 1 • Subtitle 1 • Subtitle 2

    • Title 2 • Subtitle 1 Better IDE/text editors support
  18. Agenda • Title 1 • Subtitle 1 • Subtitle 2

    • Title 2 • Subtitle 1 Compiler to take care of us
  19. Requirements • Statically typed • More powerful syntax with similar

    semantics • Possibly superset of JavaScript
  20. Languages aiming to “fix” JS TypeScript CoffeeScript ClojureScript Dart Elm

    ToffeeScript Coco Caffeine Jack LispyScript GorillaScript LiteScript asm.js JSX Typecast.js PureScript AtScript Flow Pyjamas
  21. Languages aiming to “fix” JS TypeScript CoffeeScript ClojureScript Dart Elm

    ToffeeScript Coco Caffeine Jack LispyScript GorillaScript LiteScript asm.js JSX Typecast.js PureScript AtScript Flow Pyjamas
  22. TypeScript is: • Statically typed ✓ Has compiler ✓ Has

    better IDE/text editors support • Superset of ECMAScript 2015+ ✓ Is easier to learn ✓ Has syntax sugar
  23. TypeScript is: • Statically typed ✓ Has compiler ✓ Has

    better IDE/text editors support • Superset of ECMAScript 2015+ ✓ Is easier to learn ✓ Has syntax sugar
  24. TypeScript is: • Statically typed ✓ Has compiler ✓ Has

    better IDE/text editors support • Superset of ECMAScript ✓ Is easier to learn ✓ Has syntax sugar
  25. TypeScript is: • Statically typed ✓ Has compiler ✓ Has

    better IDE/text editors support • Superset of ECMAScript ✓ Is easier to learn ✓ Has syntax sugar
  26. In loading a SPA • DNS resolution • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  27. In loading a SPA • DNS lookup • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  28. In loading a SPA • DNS lookup • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  29. In loading a SPA • DNS lookup • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  30. In loading a SPA • DNS lookup • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  31. In loading a SPA • DNS lookup • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  32. In loading a SPA • DNS lookup • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  33. In loading a SPA • DNS lookup • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  34. In loading a SPA • DNS resolution • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  35. In loading a SPA • DNS resolution • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  36. In loading a SPA • DNS resolution • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns • Minification • Concatenation • Sprites • HTTP 2.0
  37. In loading a SPA • DNS resolution • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns • Minification • Concatenation • Sprites • HTTP 2.0 • Deferred script parsing
  38. In loading a SPA • DNS resolution • Establishment of

    a TCP connection • Establishment of secure connection • Fetching all the resources • Blocking scripts • Parsing all the JavaScript files • Bootstrapping the application • Rendering the content Slowdowns
  39. What if… • Make a request to the server with

    our SPA URL • Server: • Parses the URL • Invokes the JavaScript associated to it • Returns the markup generated by the JavaScript • Browser adds event listeners to the server generated DOM
  40. Server-side rendering • Render our single-page application on the server

    • SEO friendly applications • Improved user experience
  41. Resources • Flux Overview • Flux in Depth. Overview and

    Components. • Flux in Depth. Store and Network Communication. • TypeScript • Angular 2 • React server-side rendering • Angular 2 server-side rendering