partytown README

The project's README from github.com/QwikDev/partytown. As one markdown file: README.md.

Partytown 🎉

Partytown github fit 2x

A fun location for your third-party scripts to hang out

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.

Note: Partytown is still in beta and not guaranteed to work in every scenario. Please see our FAQ and Trade-Off sections for more info.

The philosophy is that the main thread should be dedicated to your code, and any scripts that are not required to be in the critical path should be moved to a web worker. Main thread performance is, without question, more important than web worker thread performance.

Without Partytown and With Partytown: Your code and third-party code compete for main thread resources

Community



Made with love by Builder.io

partytown (QwikDev/partytown)

Searching Database…

13.8K ·GitHub
这是什么?Partytown 是一个懒加载的库,它把占用大量资源的第三方脚本从主线程移到 Web Worker 中运行,从而把主线程留给你自己的代码。
它是框架还是库?它是一个可以直接引入网页的库,而不是框架。它会拦截第三方的 ` ` 标签,并把这些脚本对 DOM 的访问代理到 Web Worker 中。
我该怎么把它加到项目里?按照 Getting Started 指南把 Partytown 添加到你的网站中。另外,对于常用的框架和页面构建工具,还有现成的集成方案。
运行或构建它需要什么?构建或开发时需要 Node >=18。如果只是在网页中使用,只要引入 Partytown 的 Worker 脚本即可,文档中没有列出任何后端依赖。
装好之后,它对所有第三方脚本都开箱即用吗?不是。该项目明确仍处于 beta 阶段,不保证在所有场景下都能正常工作。在依赖它之前,请先看看文档中列出的各项权衡取舍。
它在哪里运行?是在浏览器里吗?它完全在浏览器中运行,使用 Web Worker 作为被转移脚本的执行环境。
它是为哪类脚本设计的?通常是分析统计、广告以及其他第三方嵌入内容。这些脚本体积大,但并不属于应用的核心逻辑。把它们移到 Worker 中运行,可以让主线程专注于你自己的代码。
把脚本移到 Web Worker 上为什么能提升性能?在主线程上运行的脚本会与应用的渲染和交互争抢资源。Partytown 会代理 DOM 访问,让这些脚本改在 Web Worker 中执行,从而改善 Lighthouse、Core Web Vitals 等指标。
有没有现成的主流框架集成方案?有。Partytown 提供了 Integrations 部分,涵盖常见的使用场景,你不必手动编写 Worker 代理逻辑。
Creator
QwikDev
Size
22.7 MB
Stars
13.8K
Age
5y
Commits · 90 Days