Skip to content

Proposal: ScriptV2 bundler#5449

Merged
macobo merged 13 commits intomasterfrom
tracker-script-bundler
Jun 4, 2025
Merged

Proposal: ScriptV2 bundler#5449
macobo merged 13 commits intomasterfrom
tracker-script-bundler

Conversation

@macobo
Copy link
Copy Markdown
Contributor

@macobo macobo commented Jun 2, 2025

Changes

This PR proposes using rollup as a bundler for tracker script.

Benefit:

  • Splits the code across multiple files

Drawbacks:

  • More dependencies
  • It increases the legacy script size due to needing to use config.domain/config.endpoint/config.autoCapturePageviews over vars and new function definitions - this doesn't minify as nicely. See comment below for stats.

Best reviewed commit-by-commit.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 2, 2025

Analyzed 1025 tracker script variants for size changes.
The following tables summarize the results, with comparison with the baseline version in parentheses.

Main variants:

Brotli Gzip Uncompressed
plausible-web.js 2281B (-1B / 0%) 2601B (-10B / -0.4%) 6123B (+93B / +1.5%)

Important legacy variants:

Brotli Gzip Uncompressed
plausible.js 1140B (+24B / +2.2%) 1329B (+31B / +2.4%) 2883B (+152B / +5.6%)
plausible.hash.js 1103B (+19B / +1.8%) 1294B (+26B / +2.1%) 2769B (+146B / +5.6%)
plausible.pageview-props.tagged-events.js 1842B (+16B / +0.9%) 2145B (+35B / +1.7%) 4797B (+134B / +2.9%)
plausible.file-downloads.hash.pageview-props.revenue.js 1657B (+19B / +1.2%) 1954B (+26B / +1.3%) 4139B (+134B / +3.3%)
plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js 2248B (+24B / +1.1%) 2656B (+37B / +1.4%) 5937B (+138B / +2.4%)

Summary:

Brotli Gzip Uncompressed
Largest variant (plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js) 2248B (+24B / +1.1%) 2656B (+37B / +1.4%) 5937B (+138B / +2.4%)
Max change (plausible.compat.local.revenue.js) 1040B (+36B / +3.6%) 1246B (+35B / +2.9%) 2690B (+152B / +6%)
Min change (plausible.exclusions.hash.local.manual.revenue.js) 1052B (-3B / -0.3%) 1277B (+19B / +1.5%) 2547B (+126B / +5.2%)
Median change 1696B (+21B / +1.2%) 2006B (+28B / +1.4%) 4316B (+128B / +3%)

In total, 1014 variants brotli size increased and 8 variants brotli size decreased.

@macobo macobo marked this pull request as ready for review June 3, 2025 07:36
@macobo macobo requested review from apata and ukutaht June 3, 2025 07:36
@apata
Copy link
Copy Markdown
Contributor

apata commented Jun 3, 2025

Fleshing out the benefits and drawbacks more, I see the following

  • probably increased development ease from better code organization
  • maybe increased risk of invalid code from needing to consider module to module interactions
    • (can be mitigated with linter, maybe typescript)
  • increased supply chain attack risk from additional binary
  • script size increase

@macobo Did you already try organizing the code in the single file? If you did and found it still hard to comprehend, then I think the drawbacks, small as they are, are acceptable. Even if you didn't try that, I'd be ok with us proceeding with rollup for sake of development velocity.

Copy link
Copy Markdown
Contributor

@apata apata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After going through the changes, it is easier to understand now, especially engagement. Good job!

I'm worried that I might have missed some accidental changes during the refactor though, for features that the tests don't cover. Third set of eyes on this maybe?

Edit: Ah, I see that there was already a third set of eyes on it, good!

@macobo macobo force-pushed the tracker-script-bundler branch from a9f0e49 to ac2a119 Compare June 3, 2025 10:40
@macobo macobo enabled auto-merge June 4, 2025 07:31
@macobo macobo mentioned this pull request Jun 4, 2025
4 tasks
@macobo macobo added this pull request to the merge queue Jun 4, 2025
Merged via the queue into master with commit 426ae49 Jun 4, 2025
10 checks passed
@macobo macobo deleted the tracker-script-bundler branch June 4, 2025 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants