Lessons from open-source: Partytown — a library that uses web worker to run third party scripts.
Ramu Narasinga
Posted on March 14, 2024
This lesson is picked from Next.js source code. In this article, you will learn what a Partytown library is and where to find the code related to Partytown in Next.js
What is a partytown?
Partytown is an open source library built by Builder.io to relocate resource intensive third-party scripts into a web worker so that main thread is dedicated to your code.
Partytown is a lazy-loaded library to help relocate resource intensive scripts into a_ web worker, and off of the main thread. Its goal is to help speed up sites by dedicating the main thread to your code, and offloading third-party scripts to a web worker. — Source
Keep in mind, this library is still in beta and cannot be guaranteed to work in every scenario.
I found the following concepts that require further reading:
Where to find the code related to Partytown in next.js?
Notice that Partytown is not bundled in the next.js source code, it is supposed to be like that.
Practice the exercises based on documentation to become an expert in Next.js
Different ways to install Partytown in Next.js:
- Add Partytown type attribute to Third-Party Scripts
- Add Partytown snippet to the
- Copy Partytown library files
Conclusion:
I came across Partytown built by Builder.io when I was reading the pages/_document.tsx in the Next.js source code and wanted to find out what it is about.
Partytown helps to speed up sites by running third party scripts in a web worker and this allows the main thread dedicated only to your code. Partytown is still in beta and not guaranteed to work in every scenario. This also made me read the MDN docs related to web workers.
Get free courses inspired by the best practices used in open source.
About me:
Website: https://ramunarasinga.com/
Linkedin: https://www.linkedin.com/in/ramu-narasinga-189361128/
Github: https://github.com/Ramu-Narasinga
Email: ramu.narasinga@gmail.com
Posted on March 14, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
March 19, 2024
March 14, 2024
March 11, 2024