Third-Party Scripts: Surviving the Wild West of the Web

This ad is not shown to multipass and full ticket holders
React Summit US
React Summit US 2025
November 18 - 21, 2025
New York, US & Online
The biggest React conference in the US
Learn More
In partnership with Focus Reactive
Upcoming event
React Summit US 2025
React Summit US 2025
November 18 - 21, 2025. New York, US & Online
Learn more
Bookmark
Rate this content

As third-party script developers, we constantly work in environments we don't fully control. We must handle unexpected issues introduced by different browsers, quirky customizations made by the primary developer team, and security restrictions we can't easily bypass. In this introductory-level session, I will share first-hand experiences and practical guidance derived from building and deploying third-party scripts to improve your team's confidence and workflow efficiency.

This talk has been presented at JSNation 2025, check out the latest edition of this JavaScript Conference.

FAQ

Affirm.js is a third-party script library developed by Anton Zaldinov's firm, designed to run on various websites to provide additional functionality.

The main challenges include dealing with environments outside the developer's control, ensuring compatibility with various web technologies, and maintaining security and performance.

Affirm.js tracks approximately 93 million daily events, highlighting the importance of robust development and understanding the third-party landscape.

Async allows scripts to download without blocking HTML parsing and executes when ready, while defer also downloads without blocking but waits to execute until after HTML parsing.

Defensive coding is crucial because third-party scripts operate in environments the developers do not control, and they must account for potential conflicts with other scripts and web elements.

Developers use tools like Chrome DevTools local overrides to test scripts in real-world environments and simulate various conditions to ensure robustness and stability.

Efficient loading, using techniques like async, defer, tree shaking, and code splitting, minimizes impact on page load times and improves performance.

Security is ensured by designing for content security policy compatibility, setting up correct CORS, and considering fourth-party scripts from dependencies.

Techniques such as using the Shadow DOM help encapsulate scripts, preventing style and script interference with the host page.

Testing under diverse conditions ensures scripts are resilient and degrade gracefully, handling various HTML structures, CSS conflicts, and network conditions effectively.

Anton Zalaldinov
Anton Zalaldinov
10 min
16 Jun, 2025

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Anton Zaldinov, senior software engineer, discusses challenges in third-party script development, emphasizing the importance of defensive coding, performance, debugging, and security. Strategies include adapting to privacy changes, efficient script loading, encapsulation, and thorough testing for reliability and security.

1. Exploring Third-Party Scripts

Short description:

Anton Zaldinov, senior software engineer, delves into the challenges of third-party scripts and the critical development and deployment phases for ensuring reliability and security.

Hi, everyone. Thanks for tuning in. I'm Anton Zaldinov, a senior software engineer at the firm. Today, I'm excited to take you for the journey into the third-party scripts, surviving the wild west of the web. We'll explore the unique challenges and rewards of building code that runs on the website with an own.

So a bit about me. I work at the firm, and my primary focus is Affirm.js, which is our main third-party script library. My day-to-day involves writing and maintaining the script, ensuring it performs reliably and securely across thousands of the websites, environments that are completely outside of our control. When I talk about rich, Affirm.js operates at significant scale across many different websites.

This graph, for instance, shows event tracking specifically from Affirm.js. We're looking at around 93 million daily events. This volume underscores why robust development and understanding third-party landscapes are so crucial. The lifecycle of a third-party script starts with the local development, where we simulate varied web developments it will encounter. Then we craft the HTML snippet for the website owners.

Deployment involves minifications, CDNs, and versioning. The integrator embeds it, and our job continues with monitoring and maintenance. This monitor-and-maintain phase is highly iterative, often involving feedback loops from integrators and performance data to drive further improvements and ensure long-term stability. Let's look closer at development. Deployment locally means replicating the cross-domain reality. A key technique I use extensively is Chrome DevTools local overrides. This allows me to go to an actual integrated website that's already using our script and tell my browser to replace the live, deployed version of the third-party scripts with the version running from my local machine.

2. Challenges of Third-Party Script Development

Short description:

Live testing catches issues on integrator pages. Understanding Async and defer is vital. Scripts run in uncontrollable environments, posing challenges. Defensive coding and performance are key for survival. Debugging and security are top priorities for third-party scripts.

This is useful for testing new features and bug fixes in a complex e-commerce environment before they go live. Crucially, this live testing catches tricky issues, like CSS or script conflicts, on the integrator live page that mock setups often overlook. This script snippet is a handshake between the third-party script provider and the integrator. Here's our example. You will notice this script is loaded with Async. While this specific script handles it, it's vital for developers and integrators to understand Async and defer when dealing with a third-party script. Async downloads without blocking HTML parsing, and executes when ready, potentially interrupting parsing. Defer also downloads without blocking, but waits to execute until HTML parsing. In order, both are key for performance.

If there is one core takeaway, it's this. Any third-party script executes in an environment its developers fundamentally do not control on many different websites. This fact is the source of most unique challenges. We face as third-party script developers. It means we can make any assumptions about existing JavaScript, CSS, or even the HTML structure of the pages where our code will run. This uncertainty dictates our entire approach to design, develop, and testing. Every integration is a potential new set of variables, making robust, acceptable code not just a goal, but necessity for survival in this complex ecosystem.

Here's a concrete example from my experience. This code shows window fetch, a standard browser API, being completely overridden by another script on a host page. Our script, expecting normal workspace behavior, suddenly encounters the years or fails silently. This highlights why third-party script developers must code defensively and anticipate that global environment might not be in its default state. Beyond modified natives, third-party developers constantly navigate the global namespace, a complex web of potential variable clutches. Page loading is another common challenge. UI elements from a script must look right and function correctly despite the diverse host page CSS. Performance is paramount. Third-party scripts must be highly efficient to minimize the impact on page load times. Consider that median JavaScript payload in 2024 is over 550 kilobytes on a mobile, and a good chunk of that often comes from third-party sources, so every byte counts. And then there's debugging, when an issue only appears on a specific integrator's site out of the thousands. Reproducing and diagnosing that can be a real detective story for a script developer. Security is a top priority for any third-party script. Security is crucial to protect against vulnerabilities.

3. Strategies for Third-Party Script Development

Short description:

Developers adapt to evolving privacy landscape. Efficient script loading and encapsulation are crucial. Defensive coding, security design, and thorough testing are essential for third-party scripts.

Developers also consider fourth-party scripts from dependencies. On top of that, the privacy landscape is always evolving. The phase-out of third-party cookies, driven by growing user privacy concerns and regulatory pressures, significantly impacts traditional methods for tracking and personalization. This shift requires all web developers, especially those working with embedded content, to master new browser APIs like Chips or Storage Access API to build user-centric solutions that respect privacy.

How do third-party script developers survive and thrive? First, efficient script loading is crucial, using async and defer appropriately to minimize script size. Techniques like tree shaking or code splitting are vital to ensure only necessary JavaScript is sent to the client, reducing load times. Second, strong walls for encapsulation are essential. Shadow DOM allows developers to create isolated DOM trees for their UI scripts, reducing system conflicts and JavaScript interference from the host page.

Defensive coding is non-negotiable, as developers must check global objects and use feature detection. Bundling all dependencies using tools like Webpack helps isolate the content of the script, while designing for security from the start is key. Testing is critical, going beyond standard tuning and integration tests to simulate diverse web conditions. Developing third-party scripts is a unique adventure with challenges but also rewarding, powering crucial functionalities across the web. The job of the third-party script developer is to ensure their script works well on every website.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Node Congress 2022Node Congress 2022
26 min
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Top Content
The talk discusses the importance of supply chain security in the open source ecosystem, highlighting the risks of relying on open source code without proper code review. It explores the trend of supply chain attacks and the need for a new approach to detect and block malicious dependencies. The talk also introduces Socket, a tool that assesses the security of packages and provides automation and analysis to protect against malware and supply chain attacks. It emphasizes the need to prioritize security in software development and offers insights into potential solutions such as realms and Deno's command line flags.
Install Nothing: App UIs With Native Browser APIs
JSNation 2024JSNation 2024
31 min
Install Nothing: App UIs With Native Browser APIs
Top Content
This Talk introduces real demos using HTML, CSS, and JavaScript to showcase new or underutilized browser APIs, with ship scores provided for each API. The dialogue element allows for the creation of modals with minimal JavaScript and is supported by 96% of browsers. The web animations API is a simple and well-supported solution for creating animations, while the view transitions API offers easy animation workarounds without CSS. The scroll snap API allows for swipers without JavaScript, providing a smooth scrolling experience.
The State of Passwordless Auth on the Web
JSNation 2023JSNation 2023
30 min
The State of Passwordless Auth on the Web
Passwords are terrible and easily hacked, with most people not using password managers. The credential management API and autocomplete attribute can improve user experience and security. Two-factor authentication enhances security but regresses user experience. Passkeys offer a seamless and secure login experience, but browser support may be limited. Recommendations include detecting Passkey support and offering fallbacks to passwords and two-factor authentication.
Pushing the Limits of Video Encoding in Browsers With WebCodecs
JSNation 2023JSNation 2023
25 min
Pushing the Limits of Video Encoding in Browsers With WebCodecs
Top Content
Watch video: Pushing the Limits of Video Encoding in Browsers With WebCodecs
This Talk explores the challenges and solutions in video encoding with web codecs. It discusses drawing and recording video on the web, capturing and encoding video frames, and introduces the WebCodecs API. The Talk also covers configuring the video encoder, understanding codecs and containers, and the video encoding process with muxing using ffmpeg. The speaker shares their experience in building a video editing tool on the browser and showcases Slantit, a tool for making product videos.
5 Ways You Could Have Hacked Node.js
JSNation 2023JSNation 2023
22 min
5 Ways You Could Have Hacked Node.js
Top Content
The Node.js security team is responsible for addressing vulnerabilities and receives reports through HackerOne. The Talk discusses various hacking techniques, including DLL injections and DNS rebinding attacks. It also highlights Node.js security vulnerabilities such as HTTP request smuggling and certification validation. The importance of using HTTP proxy tunneling and the experimental permission model in Node.js 20 is emphasized. NearForm, a company specializing in Node.js, offers services for scaling and improving security.
Content Security Policy with Next.js: Leveling Up your Website's Security
React Summit US 2023React Summit US 2023
9 min
Content Security Policy with Next.js: Leveling Up your Website's Security
Top Content
Watch video: Content Security Policy with Next.js: Leveling Up your Website's Security
Lucas Estevão, a Principal UI Engineer and Technical Manager at Avenue Code, discusses how to implement Content Security Policy (CSP) with Next.js to enhance website security. He explains that CSP is a security layer that protects against cross-site scripting and data injection attacks by restricting browser functionality. The talk covers adding CSP to an XJS application using meta tags or headers, and demonstrates the use of the 'nonce' attribute for allowing inline scripts securely. Estevão also highlights the importance of using content security reports to identify and improve application security.

Workshops on related topic

Hands-On Workshop: Introduction to Pentesting for Web Apps / Web APIs
JSNation US 2024JSNation US 2024
148 min
Hands-On Workshop: Introduction to Pentesting for Web Apps / Web APIs
Featured Workshop
Gregor Biswanger
Gregor Biswanger
In this hands-on workshop, you will be equipped with the tools to effectively test the security of web applications. This course is designed for beginners as well as those already familiar with web application security testing who wish to expand their knowledge. In a world where websites play an increasingly central role, ensuring the security of these technologies is crucial. Understanding the attacker's perspective and knowing the appropriate defense mechanisms have become essential skills for IT professionals.This workshop, led by the renowned trainer Gregor Biswanger, will guide you through the use of industry-standard pentesting tools such as Burp Suite, OWASP ZAP, and the professional pentesting framework Metasploit. You will learn how to identify and exploit common vulnerabilities in web applications. Through practical exercises and challenges, you will be able to put your theoretical knowledge into practice and expand it. In this course, you will acquire the fundamental skills necessary to protect your websites from attacks and enhance the security of your systems.
0 to Auth in an hour with ReactJS
React Summit 2023React Summit 2023
56 min
0 to Auth in an hour with ReactJS
WorkshopFree
Kevin Gao
Kevin Gao
Passwordless authentication may seem complex, but it is simple to add it to any app using the right tool. There are multiple alternatives that are much better than passwords to identify and authenticate your users - including SSO, SAML, OAuth, Magic Links, One-Time Passwords, and Authenticator Apps.
While addressing security aspects and avoiding common pitfalls, we will enhance a full-stack JS application (Node.js backend + React frontend) to authenticate users with OAuth (social login) and One Time Passwords (email), including:- User authentication - Managing user interactions, returning session / refresh JWTs- Session management and validation - Storing the session securely for subsequent client requests, validating / refreshing sessions- Basic Authorization - extracting and validating claims from the session token JWT and handling authorization in backend flows
At the end of the workshop, we will also touch other approaches of authentication implementation with Descope - using frontend or backend SDKs.
OWASP Top Ten Security Vulnerabilities in Node.js
JSNation 2024JSNation 2024
97 min
OWASP Top Ten Security Vulnerabilities in Node.js
Workshop
Marco Ippolito
Marco Ippolito
In this workshop, we'll cover the top 10 most common vulnerabilities and critical security risks identified by OWASP, which is a trusted authority in Web Application Security.During the workshop, you will learn how to prevent these vulnerabilities and develop the ability to recognize them in web applications.The workshop includes 10 code challenges that represent each of the OWASP's most common vulnerabilities. There will be given hints to help solve the vulnerabilities and pass the tests.The trainer will also provide detailed explanations, slides, and real-life examples in Node.js to help understand the problems better. Additionally, you'll gain insights from a Node.js Maintainer who will share how they manage security within a large project.It's suitable for Node.js Developers of all skill levels, from beginners to experts, it requires a general knowledge of web application and JavaScript.
Table of contents:- Broken Access Control- Cryptographic Failures- Injection- Insecure Design- Security Misconfiguration- Vulnerable and Outdated Components- Identification and Authentication Failures- Software and Data Integrity Failures- Security Logging and Monitoring Failures- Server-Side Request Forgery
How to Build Front-End Access Control with NFTs
JSNation 2024JSNation 2024
88 min
How to Build Front-End Access Control with NFTs
WorkshopFree
Solange Gueiros
Solange Gueiros
Understand the fundamentals of NFT technology and its application in bolstering web security. Through practical demonstrations and hands-on exercises, attendees will learn how to seamlessly integrate NFT-based access control mechanisms into their front-end development projects.
Finding, Hacking and fixing your NodeJS Vulnerabilities with Snyk
JSNation 2022JSNation 2022
99 min
Finding, Hacking and fixing your NodeJS Vulnerabilities with Snyk
Workshop
Matthew Salmon
Matthew Salmon
npm and security, how much do you know about your dependencies?Hack-along, live hacking of a vulnerable Node app https://github.com/snyk-labs/nodejs-goof, Vulnerabilities from both Open source and written code. Encouraged to download the application and hack along with us.Fixing the issues and an introduction to Snyk with a demo.Open questions.
Bring Code Quality and Security to your CI/CD pipeline
DevOps.js Conf 2022DevOps.js Conf 2022
76 min
Bring Code Quality and Security to your CI/CD pipeline
Workshop
Elena Vilchik
Elena Vilchik
In this workshop we will go through all the aspects and stages when integrating your project into Code Quality and Security Ecosystem. We will take a simple web-application as a starting point and create a CI pipeline triggering code quality monitoring for it. We will do a full development cycle starting from coding in the IDE and opening a Pull Request and I will show you how you can control the quality at those stages. At the end of the workshop you will be ready to enable such integration for your own projects.