- Typescript Daily
- Posts
- Frontend Web Marvels: Unveiling the Secrets of Three Game-Changing Case Studies
Frontend Web Marvels: Unveiling the Secrets of Three Game-Changing Case Studies
Explore the frontiers of web development as we dive into the tech triumphs of Heap, Terra, and Grammarly. Discover how they reshaped the digital landscape.
In the ever-evolving landscape of technology and development, making informed decisions is paramount. In this newsletter article, we delve into the insights provided by three distinct case studies, each offering a unique perspective on how businesses and developers navigate challenges and embrace solutions in their respective domains.
We begin by exploring the realm of Grammarly, where the challenge lies in seamlessly integrating their browser extension into diverse websites. This case study showcases the intricate process of making Grammarly feel "native" on every website, emphasizing the importance of adaptability and user experience in extension development.
Next, we venture into the world of Terra, one of Brazil's largest content portals. Terra's case study illustrates the impact of prefetching resources on web performance, revealing how strategic data prefetching led to remarkable improvements in ad click-through rates and the Largest Contentful Paint (LCP) times.
Lastly, we dive into the transformation of Heap as they bid farewell to CoffeeScript and welcomed TypeScript into their development stack. This journey sheds light on the critical aspects of selecting a programming language that enhances code quality, maintainability, and development efficiency.
Together, these case studies provide valuable insights into the decisions, strategies, and innovations that drive success in the world of technology and development. Each story offers a unique lesson that can be applied to a wide range of projects and industries, highlighting the ever-evolving nature of our digital landscape. Let's embark on this journey to discover the lessons learned and the solutions found by Heap, Terra, and Grammarly.
Letβs Begin β¦
Case Study 1: Making Grammarly Feel Native On Every Website
In the digital age, browser extensions have become indispensable tools for users seeking to enhance their online experiences. Grammarly, a popular writing assistant, aspires to seamlessly integrate its extension into every website, regardless of its complexity and structure. Sergey Yavnyi's case study, "Making Grammarly Feel Native On Every Website," delves into the challenges faced and the innovative solutions developed to achieve this ambitious goal. This summary outlines the key takeaways from the case study, highlighting the methods used to ensure Grammarly's extension feels like a native component on all websites.
Key Points:
The Challenge of Web Diversity: With approximately two billion websites online, each presenting a unique design and structure, ensuring Grammarly's extension works seamlessly on all of them is a daunting task.
The Underlining Dilemma: A major challenge lies in rendering Grammarly's signature underlines on web content. Existing approaches involve adding underlines directly within text fields, but this method has limitations.
Issues with Direct Implementation: Adding underlines to text fields can lead to problems such as corrupting text, crashing website code, or causing unwanted formatting changes.
The Prevalence of Rich Text Editors: Many websites use rich text editors and UI frameworks, making it essential for Grammarly to support these elements to remain relevant.
A New Direction: To address these challenges, Grammarly needed to rethink its extension's approach. It aimed to minimize interference with website code while maintaining a seamless user experience.
Prototype for Underline Placement: An early prototype demonstrated placing underlines outside the text field, ensuring they did not interfere with the content while still highlighting errors effectively.
Tracking Text Field Changes: To create a seamless user experience, it was crucial to detect changes in the text field, including content changes, window scrolling, resizing, and more.
The Role of IntersectionObserver: The IntersectionObserver API was utilized to detect changes in the text field's size and position, providing precise positioning information.
Fallback with Polling: Polling was employed as a fallback mechanism to ensure that underlines aligned correctly in situations where other methods might fall short.
Performance Considerations: Frequent calls to methods like getBoundingClientRect() and getComputedStyle() had the potential to impact performance significantly.
Optimizations: Techniques were developed to reduce the number of coordinate calculations and update underlines only when necessary, improving overall performance.
Complex Layout Challenges: Complex layouts, such as pop-up dialogs and sticky headers, posed additional challenges that needed to be addressed for a seamless experience.
Conclusion, Learnings, and Impact:
In conclusion, Grammarly's journey to make its extension feel native on every website has been a challenging yet transformative one. The learnings from this case study include:
The need for innovative solutions to cater to the diversity of web structures.
The importance of minimizing interference with website code while providing a seamless user experience.
The significance of optimizing performance for browser extensions to avoid causing lag or slowing down web browsing.
The impact of this effort is substantial. Grammarly has managed to improve its compatibility with various websites, ensuring that users can enjoy its writing assistance without disruptions. By addressing these challenges head-on, Grammarly continues to enhance the writing experience for millions, reaffirming its commitment to making the web a more grammatically correct place.
In the digital realm, page load speed is a critical factor that can significantly impact user experience and business metrics. This case study explores how prefetching techniques were employed by Terra, one of Brazil's largest content portals, to accelerate page loading, resulting in impressive improvements in ads click-through rates (CTR) and a reduction in Largest Contentful Paint (LCP) times. Guilherme Moser de Souza and Thierno Thiam share insights into Terra's journey of implementing prefetching strategies to optimize their website.
Key Points:
Prefetching for Faster Loading: Prefetching is a technique that involves downloading resources or entire pages expected to be needed shortly, ultimately speeding up page loading times. Research indicates that faster load times enhance user experiences and increase conversion rates.
Terra's Scale: Terra, a prominent content portal in Brazil, caters to over 63 million unique visitors each month, offering a wide range of content, including entertainment, news, and sports.
Prefetching Strategy: Prefetching, though beneficial, must be used thoughtfully due to its consumption of extra bandwidth. Terra's prefetching approach focuses on specific conditions to avoid unnecessary data usage:
Visibility of links to prefetched articles, monitored using the Intersection Observer API.
Network and device conditions, such as a minimum 3G connection speed and at least 4GB of device memory.
CPU idle status, determined using the requestIdleCallback to avoid overloading the main thread.
Prefetched Sections: Terra selectively prefetches articles in the "Related Content" and "Recommended for you" sections of their website.
Business Impact: To measure the impact of prefetching, Terra initially introduced this feature in the "Related content" section. After two weeks of A/B testing, they expanded it to the "Recommended for you" section. The results were noteworthy:
Mobile Ads CTR increased by 11%.
Desktop Ads CTR improved by an impressive 30%.
Ads viewability increased by 10.5% on mobile and 6% on desktop.
Largest Contentful Paint (LCP) decreased by 51% on mobile and 73% on desktop.
Time to First Byte (TTFB) decreased significantly by 83% on mobile and 84% on desktop.
Technical Details: Prefetching can be achieved through various methods, such as resource hints (rel=prefetch), libraries like quicklink or Guess.js, or newer approaches like the Speculation Rules API. Terra used the fetch API with low priority and an Intersection Observer instance for their implementation, ensuring compatibility with Safari.
JavaScript Implementation: The JavaScript code used by Terra for prefetching selectively loads resources based on various conditions, including network speed, device memory, and CPU idle status.
Conclusion, Learnings, and Impact:
In conclusion, Terra's strategic implementation of prefetching, when used judiciously, led to significant improvements in page load times and crucial business metrics. The key takeaways from this case study are:
Prefetching, when applied thoughtfully, can substantially reduce load times, enhancing the user experience and engagement.
Careful consideration of network conditions and device capabilities is crucial to avoid unnecessary data usage.
Terra's dedication to optimizing performance through prefetching has led to remarkable increases in Ads CTR and decreased LCP and TTFB times.
Terra's successful journey in prefetching underscores the importance of optimizing page load speed to enhance user experiences and ultimately improve business metrics, reinforcing its position as a leading content portal in Brazil. Special acknowledgments were made to key contributors and the engineering team at Terra for their valuable contributions to this endeavor.
Case Study 3: Goodbye CoffeeScript, Hello TypeScript
This case study delves into the decision-making process behind switching from CoffeeScript to TypeScript at Heap, a company dealing with complex front-end development for web applications. It emphasizes the need for a language that is easy to reason about and accelerates development speed.
Key Points:
CoffeeScript Shortcomings:
CoffeeScript, previously popular at Heap, had its pros and cons.
Pros included a minimalistic syntax with syntax sugar and familiarity within the team.
However, the cons included issues with variable initialization, ambiguity in syntax, and the need for runtime error checking.
The Selection of TypeScript:
Heap explored various alternatives such as ClojureScript, Babel, Elm, and PureScript but ultimately chose TypeScript.
TypeScript offered built-in type annotations for documenting interfaces and enforcing correctness at compile time.
TypeScript had a clear development roadmap with rapid releases and community-type definitions for third-party JavaScript.
However, it was not yet at 100% parity with ES6 and lacked some type of system features.
Filling in the Gaps:
TypeScript introduced some language features to address the missing functionalities:
Pattern matching was implemented to reduce type casts and encourage consistent return types, reducing bugs.
Implicit conversions provided a safer alternative to monkey patching, enhancing code safety.
The introduction of "Options" declared nullability, reducing the need for duplicating ?. operators.
"Trys" declared success or failure, aiding in handling parsing errors.
"Futures" (Promises) simplified asynchronous operations, improving code maintainability.
Impact:
The adoption of TypeScript and these additional language features eliminated an entire class of null/undefined errors.
TypeScript's type system provided better guarantees, making bugs related to logic easier to track down.
The introduction of "Options," "Trys," and "Futures" enhanced code reliability and decreased ramp-up time for new developers.
Conclusion:
The shift from CoffeeScript to TypeScript at Heap proved beneficial in addressing challenges related to code maintainability and speed of development. TypeScript's type system and additional language features contributed to reducing errors, improving code quality, and simplifying complex front-end development tasks. This transition highlighted the significance of selecting a language that not only meets current needs but also supports future growth and maintainability in web application development.
π Feedback Corner
Help us refine 'TypeScript Daily' to be your go-to TypeScript guide, with a special weekly roundup. Your feedback drives our content. Share your insights and suggestions with us! Please hit reply to this email and share your thoughts.
π Wrapping It Up
Another day, another dive into the world of TypeScript. As we cross the finish line today, remember to keep exploring, keep learning, and most importantly, keep coding. If you found value in today's insights, please consider sharing this newsletter with friends or on social media β every share helps us reach more TypeScript enthusiasts like you! Stay tuned for tomorrow's journey.
Reply