The landscape of web development continuously evolves, with CSS optimization often perceived as a challenge simultaneously straightforward and deceptively complex. While fundamental techniques like minification are standard practice, the notion that all avenues for CSS efficiency have been exhausted is increasingly being challenged, particularly for a language that introduces new features almost daily. A recent investigation, leveraging a technique nearly two decades old known as UDJO, or "Using Declarations Just Once," provides compelling evidence that significant optimization potential remains untapped, even in contemporary web projects. This study, supported by a newly developed tool, CSS Dedup, demonstrates UDJO’s enduring relevance for both enhancing maintainability and reducing file sizes.
The Enduring Challenge of CSS Optimization in a Dynamic Web
CSS optimization is a critical component of web performance, directly influencing page load times, user experience, and search engine rankings (particularly with the advent of Core Web Vitals). However, its optimization is fraught with challenges. Modern web applications often feature extensive, intricately linked stylesheets, frequently incorporating frameworks, preprocessors, and third-party components. This complexity can lead to bloated CSS files, redundant declarations, and difficult-to-manage codebases. Developers are constantly seeking methods to streamline stylesheets, but many established techniques, while effective, require considerable manual effort or sophisticated tooling. The core problem often boils down to repetition: identical CSS declarations applied across multiple, distinct selectors, leading to unnecessary byte overhead and potential maintenance headaches.
Unpacking UDJO: A Principle Rooted in DRY
At its heart, UDJO is a direct application of the "Don’t Repeat Yourself" (DRY) principle, a cornerstone of software engineering that advocates for avoiding redundant code. In the context of CSS, UDJO aims to identify identical declaration blocks—such as display: flex; or color: #333;—that appear in various rules, and then consolidate them into a single rule with a comma-separated list of selectors.
Consider the following illustrative example:
.example
display: flex;
margin-top: 10px;
.sample
display: flex;
padding: 5px;
Applying the UDJO principle would transform this into:
.example,
.sample
display: flex;
.example
margin-top: 10px;
.sample
padding: 5px;
The theoretical benefits are clear: reduced file size due to fewer repeated declarations, improved cache efficiency, and significantly enhanced maintainability. When a common declaration needs to be updated, it needs to be changed in only one place, drastically reducing the potential for inconsistencies or bugs. This technique was first documented at least 18 years ago, highlighting its long-standing presence in the developer lexicon, though its widespread, systematic application has historically been limited.
Historical Context and the Rise of Automation
For many years, implementing UDJO on a large scale was largely a manual, tedious, and error-prone process. The sheer volume and complexity of modern stylesheets made it impractical for developers to meticulously scour code for every instance of repetition. The rise of CSS preprocessors like Sass and Less, while offering features for code organization and reusability (like mixins and variables), didn’t inherently solve the problem of declaration repetition at the output level. Similarly, utility-first frameworks like Tailwind CSS, while promoting a different paradigm of atomic classes, can also generate large CSS files where underlying declarations might still benefit from deduplication.
This gap between the theoretical benefit of UDJO and its practical application spurred the development of automated solutions. Recognizing the labor-intensive nature of manual deduplication for complex sites, a new tool named CSS Dedup was created. This tool’s primary function is not only to identify redundant declarations but also to safely perform the deduplication, taking into account the intricate rules of the CSS cascade. The challenge lies in ensuring that consolidating selectors does not inadvertently alter the intended styling, a critical consideration given how CSS specificity and order of appearance dictate rendered styles. CSS Dedup addresses this by providing documented mechanisms to ensure the integrity of the styles post-deduplication.
Methodology of the Empirical Study: Testing UDJO in the Wild
To assess the contemporary effectiveness of UDJO, an empirical study was conducted using CSS Dedup across two distinct sets of websites. The first batch comprised 20 arbitrarily selected general websites, representing a broad spectrum of online presences. The second batch focused on 10 websites maintained by web developers, presumably reflecting more optimized or consciously crafted CSS architectures.
For each site, CSS Dedup was applied under two specific operational modes:
- UDJO Effect (External Style Sheets) (
-f): This mode performed a "provably safe" deduplication, focusing on identifying and consolidating declarations without prioritizing immediate file size reduction. The primary goal here was to observe the structural changes and the inherent cost/benefit trade-off between reducing declarations and potentially increasing selector string lengths (e.g.,.selector1, .selector2, .selector3 ...versus.selector1 ... .selector2 ... .selector3 ...). - Aggressive With Savings Only (
-f -a -s): This mode applied a more "aggressive" deduplication strategy, but only implemented changes that resulted in a net reduction in file size. This approach is more aligned with practical performance optimization goals, where the ultimate aim is to decrease the bytes transferred.
It is crucial to note that the reported values represent changes in uncompressed file sizes. While compression techniques like Gzip or Brotli are universally applied in production, the raw file size reduction achieved by UDJO forms the foundational improvement upon which further compression can build. The study explicitly set aside post-compression analysis, focusing purely on the structural efficiency gains from deduplication.
Key Findings: Performance and Maintainability Across Diverse Websites
The analysis yielded significant insights into UDJO’s potential. The results are presented below, demonstrating the impact on external stylesheets.
Table 1: UDJO Effect on General Websites
| Site | UDJO Effect (External Style Sheets) (-f) |
Aggressive With Savings Only (-f -a -s) |
|---|---|---|
| 12371.cn | +2.9 KB (+14.3%) | -45 B (-0.2%) |
| ccc.de | +0.8 KB (+2.2%) | -0.1 KB (-0.3%) |
| commission.europa.eu | +64.9 KB (+6.4%) | -51.9 KB (-5.1%) |
| die-linke.de | +104.0 KB (+20.5%) | -21.2 KB (-4.2%) |
| diem25.org | +40.5 KB (+10.7%) | -4.4 KB (-1.2%) |
| eff.org | +120.8 KB (+27.7%) | -8.5 KB (-2.0%) |
| en.mfa.ir | +58.7 KB (+5.1%) | -51.2 KB (-4.5%) |
| euroveg.eu | +78.8 KB (+9.3%) | -12.4 KB (-1.5%) |
| globalsumudflotilla.org | -17.0 KB (-6.5%) | -18.7 KB (-7.2%) |
| gruene.de | +1.6 KB (+1.1%) | -0.7 KB (-0.5%) |
| icanw.org | +5.5 KB (+2.9%) | -3.5 KB (-1.8%) |
| laquadrature.net | +14.0 KB (+4.2%) | -3.0 KB (-0.9%) |
| middleeasteye.net | +60.9 KB (+8.6%) | -20.5 KB (-2.9%) |
| movimientosumar.es | +98.8 KB (+13.6%) | -5.0 KB (-0.7%) |
| nam.go.ug | +84.5 KB (+9.2%) | -53.9 KB (-5.9%) |
| oic-oci.org | -6.3 KB (-4.0%) | -9.3 KB (-6.0%) |
| podemos.info | +23.2 KB (+5.5%) | -6.0 KB (-1.4%) |
| taxmenow.eu | +1.7 KB (+2.1%) | -4.0 KB (-4.6%) |
| unrwa.org | +87.4 KB (+13.2%) | -4.8 KB (-0.7%) |
| veganeurope.eu | +37.3 KB (+17.7%) | -1.3 KB (-0.6%) |
The first column, UDJO Effect (-f), reveals a nuanced aspect of deduplication: many sites initially showed an increase in file size. For instance, eff.org saw a +120.8 KB (+27.7%) increase, and die-linke.de experienced a +104.0 KB (+20.5%) increase. This phenomenon occurs when the byte savings from reducing repeated declarations are outweighed by the increased length of comma-separated selector strings. For example, replacing two identical declarations each with a short selector like .a display:flex and .b display:flex with a single rule .a, .b display:flex saves the declaration bytes but adds the , .b to the selector string. If the original selectors were very short and numerous, the combined selector string could become longer than the individual selectors plus their declarations, resulting in a net increase in file size. This highlights the "intelligence" aspect of UDJO—it’s not just about finding duplicates, but about doing so efficiently.
However, the second column, Aggressive With Savings Only (-f -a -s), paints a different picture. Here, all websites demonstrated file size reductions. For instance, commission.europa.eu saw a significant -51.9 KB (-5.1%) reduction, and nam.go.ug achieved a -53.9 KB (-5.9%) saving. This indicates that when the deduplication process is intelligently configured to prioritize actual byte savings, UDJO consistently delivers performance benefits. The range of savings varied, from marginal reductions of less than 1% to substantial decreases of over 5%, demonstrating that even on highly complex sites, meaningful optimization is achievable.
Insights from Web Developer-Centric Sites
The study also examined a selection of sites maintained by web professionals, who are typically more attuned to performance and optimization best practices.
Table 2: UDJO Effect on Web Developer Sites
| Site | UDJO Effect (External Style Sheets) (-f) |
Aggressive With Savings Only (-f -a -s) |
|---|---|---|
| bram.us | +19.6 KB (+7.3%) | -4.2 KB (-1.6%) |
| ishadeed.com | +4.2 KB (+11.4%) | -0.2 KB (-0.5%) |
| joshwcomeau.com | -2.7 KB (-3.8%) | -5.0 KB (-7.2%) |
| kevinpowell.co | +0.1 KB (+0.6%) | -0.1 KB (-0.5%) |
| kizu.dev | +1.0 KB (+1.7%) | -0.1 KB (-0.2%) |
| lea.verou.me | -0.4 KB (-1.4%) | -0.6 KB (-2.3%) |
| miriamsuzanne.com | -0.2 KB (-0.5%) | -0.7 KB (-2.0%) |
| paul.kinlan.me | +3.3 KB (+8.0%) | -1.0 KB (-2.4%) |
| pawelgrzybek.com | -0.5 KB (-2.7%) | -0.7 KB (-4.3%) |
| sarasoueidan.com | -2.9 KB (-7.3%) | -4.5 KB (-11.1%) |
Similar to the general websites, the initial UDJO Effect (-f) column showed a mixed bag, with some sites experiencing slight increases and others slight decreases. However, the Aggressive With Savings Only (-f -a -s) column consistently showed file size reductions across all sites. Notably, sites like sarasoueidan.com achieved a remarkable -4.5 KB (-11.1%) reduction, and joshwcomeau.com saw a -5.0 KB (-7.2%) saving.
The findings suggest that even among web professionals, who are generally more diligent about code quality and optimization, there is still ample room for UDJO to yield benefits. The observed savings indicate that even carefully crafted stylesheets can harbor declaration redundancies that automated tools can effectively address. It could be inferred that web professionals might tend to use shorter, more modular selectors, which could make their CSS more amenable to UDJO’s benefits, as the trade-off between selector length and declaration count might be more favorable. This area warrants further investigation with a larger sample size to confirm such a hypothesis.
The Dual Impact: Maintainability and Performance
The study definitively answers the question: "Is UDJO still effective and relevant today?" The answer is a resounding yes. Its effectiveness stems from a dual impact on both maintainability and performance.
Maintainability: By consolidating identical declarations, UDJO reduces the sheer volume of code that developers need to manage. This simplifies updates, reduces the likelihood of introducing bugs due to inconsistent styling, and makes the codebase easier to onboard new team members. In large-scale projects with multiple contributors, this benefit alone can be invaluable, fostering a more robust and agile development environment.
Performance: The consistent file size reductions observed in the Aggressive With Savings Only mode directly translate to tangible performance improvements. Smaller CSS files mean less data transferred over the network, faster download times, and quicker rendering of web pages. This positively impacts Core Web Vitals metrics, enhancing user experience and potentially improving SEO rankings. While the study did not measure post-compression effects, it is logical to infer that a smaller, less redundant raw file would also likely achieve better compression ratios with Gzip or Brotli, further amplifying the performance gains.
Interactions with Broader Optimization Strategies
UDJO is not a standalone solution but a powerful complementary technique within a holistic CSS optimization strategy. It should ideally be applied before other common steps:
- Minification: UDJO reduces the content, then minification removes whitespace and shortens properties. Applying UDJO first ensures that the most compact form of the CSS is then minified.
- Compression (Gzip/Brotli): While the study focused on uncompressed sizes, UDJO’s reduction in redundancy creates patterns that compression algorithms can exploit more effectively, potentially leading to even greater overall file size reductions for the end-user.
- Critical CSS and PurgeCSS: These techniques focus on delivering only necessary CSS for the initial viewport or removing unused styles entirely. UDJO complements them by optimizing the remaining CSS, ensuring that even the necessary or persistent styles are as lean as possible.
- HTTP/2 and Beyond: Even with modern protocols that optimize resource delivery, reducing the total byte count of any asset remains a fundamental optimization. Less data always translates to faster delivery and lower bandwidth consumption, especially critical for mobile users or those on slower networks.
Challenges and Future Considerations
Despite its proven effectiveness, the implementation of UDJO, particularly through automated tools, faces certain considerations:
- The Cascade’s Nuances: The CSS cascade order is paramount. Any deduplication tool must be sophisticated enough to understand specificity and source order to ensure that consolidating rules does not inadvertently alter the intended visual output. CSS Dedup explicitly addresses this challenge in its design.
- Balancing Selector Length and Declaration Savings: As seen in the
UDJO Effect (-f)results, there’s a delicate balance. A truly intelligent tool must weigh the byte savings from declaration reduction against the potential byte increase from longer, combined selector strings. The "aggressive with savings only" mode demonstrates how this can be managed effectively. - Integration into Development Workflows: For UDJO to become a standard practice, tools like CSS Dedup need seamless integration into CI/CD pipelines, build processes, and developer tooling. This ensures consistent application without imposing significant manual overhead.
- Scope of Application: While the study focused on external stylesheets, similar principles could be applied to inline styles or styles within Shadow DOM, though with their own unique challenges.
Conclusion: A Renewed Case for a Classic Technique
The empirical data presented makes a compelling case for the continued relevance and effectiveness of UDJO in modern CSS optimization. What was once a theoretically sound but manually intensive technique has been revitalized by automated tooling, demonstrating tangible benefits in both code maintainability and raw file size reduction. The study’s findings challenge the assumption that all significant CSS optimization vectors have been fully exploited, revealing that even a decades-old principle can yield considerable gains on today’s complex web.
For web developers, performance engineers, and organizations striving for optimal web experiences, UDJO should be reconsidered as a vital component of their CSS strategy. By incorporating tools like CSS Dedup into their development workflows, teams can achieve a leaner, more performant, and more maintainable codebase. The journey toward ultimate CSS efficiency is ongoing, and UDJO stands as a testament that innovation in optimization isn’t solely about new techniques, but also about intelligently applying timeless principles with modern tools. The ceiling for CSS optimization, it seems, is still far from reached.