Performance Optimization for the Entire Process of Web Applications

In this post, I will cover the performance optimization for the entire process of web applications, including the frontend, backend, networking, and web server.

Web Frontend

Be small (splitting, compressing, minifying)

Code splitting

Purpose: Reduce a page’s initial JavaScript payloads. Avoid requesting all components or modules on the first page visit. To improve the speed of the first page visit.

Dynamic imports allow components or modules to be loaded asynchronously when they are needed.

Compress images

Purpose: Reduce the file size of images. To reduce the time it takes to load web pages.

Use image compression tools, choose the right image format, and use responsive images.

Minify CSS and JavaScript

Purpose: Reduce the file size of CSS and JavaScript files. To reduce the time it takes to load web pages.

Minify CSS and JavaScript files, remove unused CSS and JavaScript code, and use CSS and JavaScript bundling.

Be efficient (async, defer/lazy, dynamic, optimize process logic)

Lazy loading

Purpose: Load images, videos, and other resources only when they are needed. To reduce the time it takes to load web pages.

Lazy loading is a technique that defers the loading of non-critical resources at page load time.

Use web workers

Purpose: Improve the performance of web applications. To reduce the time it takes to load web pages.

Web workers allow JavaScript code to run in a separate thread, which can improve the performance of web applications by offloading CPU-intensive tasks to a separate thread.

Optimize the critical rendering path (CRP)

Purpose: Reduce the time it takes to load web pages.

Optimize the critical rendering path by minimizing the number of critical resources, reducing the number of critical bytes, and minimizing the critical path length.

Virtual scrolling

Purpose: Displays large lists of elements performantly by only rendering the items that fit on-screen. To improve the speed of rendering large lists.

Loading hundreds of elements can be slow in any browser; virtual scrolling enables a performant way to simulate all items being rendered by making the height of the container element the same as the height of total number of elements to be rendered, and then only rendering the items in view.

Virtual Scroll inherits the user experience of infinite Scroll, where the user has to scroll in order to change displayed data. However, unlike with infinite Scroll, the list does not expand. Instead, we always have a constant number of elements in memory, like with pagination.

Cache

Use a service worker

Purpose: Improve the performance of web applications. To reduce the time it takes to load web pages.

A service worker is a script that runs in the background of a web page and can intercept and cache network requests.

Networking

Use a Content Delivery Network (CDN)

Purpose: Reduce the time it takes to load web pages.

A CDN is a network of servers that deliver web content to users based on their geographic location.

Web Server - Nginx

Cache static files in browsers + Build static assets with versioning/hashing mechanisms

Purpose: Avoid repeated requests for static files. To reduce the time it takes to load web pages.

Adding Cache-Control headers to the response’s headers. Adding a version/hash to the filename or query string is a good way to manage caching.

Compress static source code files

Purpose: Reduce the file size of static source code files (css, js, xml). To reduce network transfer time for files.

Enable gzip in Nginx.

Use the HTTP/2 protocol

Purpose: Use the HTTP/2 protocol instead of HTTP/1.1. To reduce network transfer time for requests.

Enable HTTP/2 in Nginx. HTTP/2 is much faster and more efficient than HTTP/1.1.

Web Backend

Optimize database queries

Purpose: Reduce the time it takes to query the database.

Use indexes, optimize SQL statements, and optimize the database schema.

Optimize the server-side code

Purpose: Reduce the time it takes to process business logic.

Use caching, optimize algorithms, and use asynchronous processing.

Avoid query database in loops.

Optimize API

Purpose: Improve the performance of web applications.

Properly divide the functional coverage of APIs.

Respond required data only.

Operations

Use Docker

Purpose: Simplify the deployment process. To reduce the time it takes to deploy web applications.

Use Docker to package applications and their dependencies into containers.

Docker is a popular platform for developing, shipping, and running applications in containers. Here are some key benefits of using Docker:

  • Consistency Across Environments: Docker containers encapsulate an application and its dependencies, ensuring that it runs the same way in development, staging, and production.
  • Isolation: Each Docker container is isolated from others, which means multiple containers can run different versions of the same software or entirely different applications on the same host without conflicts

Use CI/CD

Purpose: Automate the deployment process. To reduce the time it takes to deploy web applications.

CI/CD is a set of practices that automate the integration and delivery of code changes to production.