Lighter than Lightweight: How We Built the Same App Twice with Preact and Glimmer.js

Overview

This article discusses the development of a prototype application using two JavaScript libraries, Preact and Glimmer.js, to explore performance optimization in web applications. It highlights the differences in philosophy between lightweight libraries and the use of compilers for achieving better performance.

What You'll Learn

1

How to compare performance between Preact and Glimmer.js in web applications

2

Why file size is not the only factor affecting web application load time

3

When to use server-side rendering versus client-side rendering for performance

Prerequisites & Requirements

  • Understanding of JavaScript frameworks and web performance metrics
  • Familiarity with webpack and TypeScript(optional)

Key Questions Answered

How do Preact and Glimmer.js compare in terms of performance?
Both Preact and Glimmer.js performed similarly in benchmarks, with Glimmer.js slightly outperforming Preact in First Meaningful Paint and rendering, while Preact had a slight edge in Time to Interactive. The differences were within hundreds of milliseconds, indicating both libraries can achieve fast load times.
What are the benefits of using lightweight libraries for web applications?
Lightweight libraries like Preact prioritize small file sizes to enhance load times, but may sacrifice some robustness. The article discusses how this approach can lead to complexity as applications grow, suggesting a balance between size and functionality is crucial.
What metrics were used to measure web application performance?
The performance metrics used included First Meaningful Paint and Time to Interactive, which help gauge how quickly the primary content appears and how soon the application is ready for user interaction. These metrics provide a more holistic view of user experience.
What role does server-side rendering play in application performance?
Server-side rendering (SSR) can significantly improve initial load times by generating HTML on the server, allowing users to see content faster. The article notes that SSR variants showed better performance in First Meaningful Paint compared to client-side rendering (CSR) variants.

Key Statistics & Figures

First Meaningful Paint (90th %ile)
2533 ms for Glimmer SSR, 2938 ms for Preact SSR
Indicates how quickly users see meaningful content.
Time to Interactive (90th %ile)
5749 ms for Preact SSR, 6323 ms for Glimmer SSR
Measures how long it takes for the application to become fully interactive.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Frontend
Preact
Used to build a lightweight version of the application.
Frontend
Glimmer.js
Used to build a version of the application focused on performance through compiled templates.
Tools
Typescript
A typed superset of JavaScript used in the project.
Tools
Webpack
Used to create optimized builds for both Preact and Glimmer.js.
Tools
CSS Blocks
A component-oriented CSS solution utilized in the prototype.

Key Actionable Insights

1
Consider implementing both Preact and Glimmer.js in your projects to evaluate their performance benefits.
By testing both libraries, you can determine which one best meets your application's needs based on real-world performance metrics.
2
Utilize server-side rendering to enhance the initial load time of your web applications.
SSR can provide users with faster access to content, which is crucial for improving user experience, especially on slower networks.
3
Balance file size and application complexity when choosing a JavaScript framework.
While smaller libraries can improve load times, they may introduce complexity as your application grows. Assess the trade-offs carefully.

Common Pitfalls

1
Relying solely on synthetic benchmarks can lead to misleading conclusions about performance.
Synthetic benchmarks may not accurately reflect real-world usage, as they don't account for variables like network conditions and user interactions.

Related Concepts

Web Performance Optimization
Javascript Frameworks Comparison
Server-side Rendering Vs Client-side Rendering