Skip to content

chore(build): investigate merging auto.js into embed.js #166

Closed as not planned
Closed as not planned

Description

@Ardnived

The question

auto.js (~3 KiB) and embed.js (~302 KiB gz) are two entries because the loader defers fetching
the widget until the embed is near the viewport. The original second reason is gone: the
classic-script bridge built for Wix was removed (git show a94a567) and no Wix client embeds
anything today, so nobody is choosing between entries — every host pastes auto.js.

So the split now buys exactly one thing: an embed below the fold costs a visitor 3 KiB instead of
302 until they scroll to it. Is that worth two entries, a chunk-disjointness assertion, a
duplicated-literals rule and a src/loader/ seam nobody may import across?

Why this is worth investigating rather than just doing

The honest answer is that merging trades a real saving for a simpler contract, and we do not
currently know the size of either side.

  • We have never measured how many embeds are actually below the fold. If most clients put the atlas
    on a dedicated page, the deferral saves nothing for them and costs everyone the seam.
  • 302 KiB gz eager is itself the thing worth attacking. The map is already lazy and is not in that
    number
    — so the eager graph is React, react-router, TanStack Query, zod, i18next, framer-motion,
    vaul and Radix. If that came down substantially, the case for deferring it weakens on its own.

What to find out

  1. Measure the eager graph properly. pnpm size gives a total; this needs a per-dependency
    breakdown. Two candidates named up front: framer-motion (drives the peek strips and a drawer
    cross-fade — both plausibly CSS) and zod (runs on every API response, so probably
    load-bearing, but worth pricing).
  2. Establish whether deferral is earning anything. The embed report already records each mount;
    it does not record whether the embed was in the initial viewport. Adding that is small and would
    answer the question with data instead of intuition.
  3. Price the merge. What actually goes away: the loader/embed split in
    scripts/check-bundle-size.mjs including the closure-disjointness assertion, the duplicated
    literals in src/loader/literals.ts and their pinning spec, and the rule that no value may be
    imported across the seam (CLAUDE.md, and feat(widget): send the embed report and publish a readiness marker #153 broke it with a one-line string join).
  4. Check what a merge would cost a host. One entry means the widget is fetched on every page
    view of every embed. On a phone on a slow connection, 302 KiB before the visitor has scrolled to
    it is not nothing.

Constraints

  • Clients must never have to pick an entry. They do not today, and any outcome that reintroduces
    that is worse than the status quo. This is the requirement, not the split.
  • The evergreen caching contract stands either way: root entries revalidate, hashed chunks are
    immutable (see docs/embedding.md → Updates and caching).
  • If the merge happens, docs/embedding.md and CHANGELOG.md both name embed.js as a file hosts
    may see, and docs(widget): publish an accurate integrator guide #93/docs(widget): publish an accurate integrator guide #144 exist because the README once named a file the build never emitted.

Definition of done

A recommendation with numbers behind it: the per-dependency breakdown of the eager graph, whatever
we can establish about below-the-fold embeds, and either a merge PR or a written reason not to.

Activity

  1. added theissue type on Aug 28, 2026
  2. Ardnived commented on Oct 28, 2026

    @Ardnived
    ContributorAuthor

    Closing as not planned, with the numbers. Measured 2026-10-27 on sahajatlas.com: auto.js and its imports are 2.8 KiB gzipped; embed.js and its imports are 312 KiB. A merge would delete only literals.ts and the no-shared-code check, because the loader logic (config, detect, most of index) is needed either way, and CI already enforces the split. Measuring below-the-fold embeds would need a SahajCloud embedMetadata schema change first. Not worth it; reopen if the split breaks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Low

    Hold Until

    Jan 20, 2027

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions