Skip to content

Use same-origin resources for compiler bundles. #1038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2025

Conversation

cometkim
Copy link
Member

@cometkim cometkim commented May 18, 2025

Compiler JS bundles are uploaded into a Cloudflare R2 bucket.

rescript-lang/rescript#7472

Serving resources from the same-origin removes CORS preflight when visiting the playground and prevents charges for R2 reads.

I made the sync-bundles script to download all resources from the bucket.

And we have two options:

  1. Commit resources to git
    • Only new versions can be additionally downloaded.
    • The repo will get significant bloat.
  2. Don't commit resources to git
    • For developers, they need to sync it at least once.
    • The sync must be run per deployment, which will significantly slow down.

Option 2 is not feasible for Vercel deployments, but for Cloudflare Pages.

Alternatively, we can run a custom deployment with GitHub Actions (When we use Cloudflare Workers instead of Pages). Option 2 + @actions/cache would be the best.

@cometkim cometkim requested a review from cknitt May 18, 2025 02:19
Copy link

vercel bot commented May 18, 2025

@cometkim is attempting to deploy a commit to the ReScript Association Team on Vercel.

A member of the Team first needs to authorize it.

@cometkim cometkim force-pushed the playground-bundles branch from 8c3553f to 59021cf Compare May 18, 2025 02:22
@cknitt cknitt requested a review from fhammerschmidt May 18, 2025 06:56
Copy link
Member

@fhammerschmidt fhammerschmidt left a comment

Choose a reason for hiding this comment

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

Then I'd say check them in until Vercel is gone and do the proper action setup later?

@cometkim
Copy link
Member Author

Once checked in, it cannot be undone. Therefore, to avoid bloating the git repository, we shouldn't check in forever.

@cometkim
Copy link
Member Author

This will work on Cloudflare pages anyway after changing the command to npm run sync-bundles && npm run build.

@cometkim
Copy link
Member Author

Then we switch to Cloudflare Workers. I'll add GitHub Actions to optimize it and get the versioned snapshot deployments and fork previews we want.

@cometkim
Copy link
Member Author

cometkim commented May 18, 2025

Ok, I'm merging it; this won't break the existing Vercel build with a few tweaks.

@cometkim cometkim force-pushed the playground-bundles branch from d3ce49f to 998b798 Compare May 18, 2025 08:43
@cometkim cometkim merged commit 66047b2 into rescript-lang:master May 18, 2025
1 of 2 checks passed
@cometkim cometkim deleted the playground-bundles branch May 18, 2025 08:45
@cometkim
Copy link
Member Author

Whoa, option 2 isn't as bad as I expected. Full sync takes only ~20s in the Cloudflare Pages build.

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.

2 participants