- Switching to Angular(Third Edition)
- Minko Gechev
- 409字
- 2021-07-02 15:23:30
Server-side rendering
The bigger the requirements of the web are, the more complex web applications become. Building a real-life, single-page application requires writing a huge amount of JavaScript, and including all the required external libraries may increase the size of the scripts on our page to a few megabytes. The initialization of the application may take up to several seconds or even tens of seconds on a mobile device until all the resources get fetched from the server, the JavaScript is parsed and executed, the page gets rendered, and all the styles are applied. On low-end mobile devices that use a mobile internet connection, this process may make the users give up on visiting our application. Although there are a few practices that speed up this process, in complex applications, there's no silver bullet.
In the process of trying to improve the user experience, developers discovered a technique called server-side rendering. It allows us to render the requested view of a single-page application on the server and directly provide the HTML for the page to the user. Later, once all the resources are processed, the event listeners and bindings can be added by the script files. This sounds like a good way to boost the performance of our application. One of the pioneers in this was React, which allowed prerendering of the user interface on the server side using Node.js DOM implementations. Unfortunately, the architecture of AngularJS does not allow this. The showstopper is the strong coupling between the framework and the browser APIs, the same issue we had in running the change detection in web workers.
Another typical use case for the server-side rendering is for building Search Engine Optimization (SEO)-friendly applications. There were a couple of hacks used in the past for making the AngularJS applications indexable by the search engines. One such practice, for instance, is the traversal of the application with a headless browser, which executes the scripts on each page and caches the rendered output into HTML files, making it accessible by the search engines.
Although this workaround for building SEO-friendly applications works, server-side rendering solves both of the aforementioned issues, improving the user experience and allowing us to build SEO-friendly applications much more easily and far more elegantly.
The decoupling of Angular with the DOM allows us to run our Angular applications outside the context of the browser. We will take a further look at it in Chapter 9, Tooling and Development Experience.
- Spring 5企業級開發實戰
- Mobile Application Development:JavaScript Frameworks
- 單片機C語言程序設計實訓100例:基于STC8051+Proteus仿真與實戰
- HBase從入門到實戰
- PHP 編程從入門到實踐
- ADI DSP應用技術集錦
- Spring Boot進階:原理、實戰與面試題分析
- Rust游戲開發實戰
- Orleans:構建高性能分布式Actor服務
- 一步一步跟我學Scratch3.0案例
- IBM Cognos TM1 Developer's Certification guide
- Photoshop CC移動UI設計案例教程(全彩慕課版·第2版)
- jQuery技術內幕:深入解析jQuery架構設計與實現原理
- UML基礎與Rose建模實用教程(第三版)
- 游戲設計的底層邏輯