server side rendering isn t enough server side rendering
play

SERVER-SIDE RENDERING ISN'T ENOUGH SERVER-SIDE RENDERING ISN'T - PowerPoint PPT Presentation

SERVER-SIDE RENDERING ISN'T ENOUGH SERVER-SIDE RENDERING ISN'T ENOUGH MATTHEW PHILLIPS MATTHEW PHILLIPS GITHUB.COM/CANJS/CAN-SSR GITHUB.COM/CANJS/CAN-SSR TERMS TERMS Shared codebase Isomorphic Universal WHY BOTHER WHY BOTHER This sucks


  1. SERVER-SIDE RENDERING ISN'T ENOUGH SERVER-SIDE RENDERING ISN'T ENOUGH

  2. MATTHEW PHILLIPS MATTHEW PHILLIPS GITHUB.COM/CANJS/CAN-SSR GITHUB.COM/CANJS/CAN-SSR

  3. TERMS TERMS Shared codebase Isomorphic Universal

  4. WHY BOTHER WHY BOTHER This sucks Perceived performance : no one likes staring at a spinner. SEO : if you care about that sort of thing, it helps. Not every bot is Googlebot. BLING BLING : Amazon reports that conversion increased by 1% for every 100ms improvement.

  5. THE STATE OF SERVER RENDERING THE STATE OF SERVER RENDERING

  6. EVERYTHING SHOULD BE SERVER RENDERED EVERYTHING SHOULD BE SERVER RENDERED

  7. REQUIREMENTS REQUIREMENTS PERFORMANCE PERFORMANCE Rendering speed Only includes the assets needed (CSS and JavaScript) Prevents unnecessary requests in the client MAINTAINABILITY MAINTAINABILITY Shared router Asynchronous rendering Fast development experience with hot module swapping

  8. RENDERING PERFORMANCE RENDERING PERFORMANCE

  9. HEADLESS BROWSER HEADLESS BROWSER PhantomJS Consumed a lot of memory Needed pooling Very fast

  10. VIRTUAL DOMS VIRTUAL DOMS Run the same code on the client and server Run within a single Node context Rendering is usually synchronous

  11. CAN-SSR'S VDOM CAN-SSR'S VDOM Looks like a real DOM, only the basics

  12. DEMO COMPATIBILITY DEMO COMPATIBILITY

  13. MINIMIZING REQUEST SIZE MINIMIZING REQUEST SIZE

  14. TRADITIONAL METHOD TRADITIONAL METHOD CSS LOADED IN JAVASCRIPT CSS LOADED IN JAVASCRIPT /cart 1. Initially unstyled 2. Main, site-wide style is loaded 3. Page specific style is loaded Title progressively.

  15. WITH SERVER TEMPLATE WITH SERVER TEMPLATE ADDING CSS MANUALLY ADDING CSS MANUALLY 1. Initially partially styled; main CSS is /cart included, most of the page-specific CSS. Title 2. Rest of page-specific styles are added.

  16. WITH DONEJS WITH DONEJS CAN-SSR DOES IT FOR YOU CAN-SSR DOES IT FOR YOU /cart 1. All styles needed for the page are included directly in the head. And only the styles needed for Title the page.

  17. COMPONENT-BASED ARCHITECTURE COMPONENT-BASED ARCHITECTURE import Framework from 'fancy-framework'; import './styles.scss'; ...

  18. MINIMIZING THE NUMBER OF REQUESTS MINIMIZING THE NUMBER OF REQUESTS

  19. PREVENT REDUNDANT REQUESTS PREVENT REDUNDANT REQUESTS Embed responses into the rendered page. Can be reused on the client to do initial rendering. <script> INLINE_CACHE = {"users": [{ ... } ] }; </script>

  20. SHARED CODE-BASE SHARED CODE-BASE

  21. HOW MUCH CODE IS SHARED? HOW MUCH CODE IS SHARED? MINIMIZING DIFFERENCES FOR EASIER MAINTAINENCE MINIMIZING DIFFERENCES FOR EASIER MAINTAINENCE The "main" can run on both client and in Node. A shared router, not adding new routes in separate places

  22. EXAMPLE EXAMPLE Middleware Core API var ssr = require("can-ssr/middleware"); var ssr = require("can-ssr"); var app = require("express")(); var render = ssr(); app.use(ssr()); render("/cart").then(function(result){ console.log(result.html); });

  23. ASYNCHRONOUS RENDERING ASYNCHRONOUS RENDERING

  24. // server.js import render from "framework-dom"; SYNCHRONOUS RENDERING SYNCHRONOUS RENDERING app.get("/cart", function(req, res){ Forces all data to be present fetchCart().then(function(data){ res.send( before rendering. render(data) ); Cannot use component- }); based architecture. }); Pushes application logic into another layer. // cart.js Makes writing reusable import Component from "fancy-framework"; components harder. class Cart extends Component { render() { let data = this.props.data; return <div> ... </div> } }

  25. DEMO ASYNCHRONOUS REACT DEMO ASYNCHRONOUS REACT

  26. HTTPS://GITHUB.COM/CANJS/CAN-WAIT HTTPS://GITHUB.COM/CANJS/CAN-WAIT

  27. INSTANT DEV WORKFLOW INSTANT DEV WORKFLOW HOT MODULE REPLACEMENT HOT MODULE REPLACEMENT

  28. DEMO DONEJS LIVE-RELOAD DEMO DONEJS LIVE-RELOAD

  29. THE END THE END BY MATTHEW PHILLIPS BY MATTHEW PHILLIPS

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend