Skip to content

feat: prebundle code + restore from snapshot#1604

Merged
marvinhagemeister merged 22 commits into
mainfrom
prebuild-2
Aug 16, 2023
Merged

feat: prebundle code + restore from snapshot#1604
marvinhagemeister merged 22 commits into
mainfrom
prebuild-2

Conversation

@marvinhagemeister

@marvinhagemeister marvinhagemeister commented Aug 7, 2023

Copy link
Copy Markdown
Contributor

This PR allows you to prebundle all islands and other code needed for the browser ahead of time. The workflow with this is that you have a GitHub action where you build the assets and then deploy from there.

Pros:

  • Files are served as quick as deploy + fresh can serve them
  • No need to fetch dependencies when an isolate spins up
  • Makes deployments reproducible since they cannot be affected by outages from third parties like esm.sh anymore
  • The bigger the island code the more noticeable the speed improvement

Cons:

  • Makes deployments 10-15s longer
  • Requires GH Actions to be set up

Assets can be generated by running deno task build and the main.ts script will pick up the snapshots automatically if one is there. When it does it prints a message to the terminal.

Screenshot 2023-08-07 at 17 47 24

The speed difference is best shown with a video. In the ahead of time (AOT) bundled version the agolia search loads nearly instantaneously. Go to https://fresh-www-test.deno.dev/ to see that for yourself.

output.mp4

The main difference to #1450 is, that this accounts for plugins and includes a way to generate the bundles + snapshots directly in Fresh.

Fixes #1062

@lino-levan

Copy link
Copy Markdown
Contributor

This is a very similar approach to what I did in #1084 for a PoC. I think this is the right way to do it. +1 for the concept.

@marvinhagemeister

Copy link
Copy Markdown
Contributor Author

Gonna do the documentation update in another PR since the deploy page needs an overall in general.

@marvinhagemeister marvinhagemeister marked this pull request as ready for review August 11, 2023 09:03
Comment thread src/dev/build.ts
Comment thread src/server/context.ts
@fdemir

fdemir commented Aug 14, 2023

Copy link
Copy Markdown
Contributor

We should add this to the documentation.

@bartlomieju bartlomieju left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀

@marvinhagemeister

Copy link
Copy Markdown
Contributor Author

Added a page to our documentation and I think the PR is ready to be merged.

@lino-levan

Copy link
Copy Markdown
Contributor

Let me take a look!

Comment thread .gitignore Outdated
Comment thread docs/canary/concepts/ahead-of-time-builds.md Outdated
Comment thread init.ts Outdated
Comment thread src/build/esbuild.ts
Comment thread src/dev/build.ts
Comment thread src/dev/build.ts Outdated
Comment thread tests/build_test.ts
Comment thread tests/build_test.ts Outdated
@marvinhagemeister marvinhagemeister merged commit 477364c into main Aug 16, 2023
@marvinhagemeister marvinhagemeister deleted the prebuild-2 branch August 16, 2023 14:47
@lino-levan

Copy link
Copy Markdown
Contributor

Nice! Excited to have this land.

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.

Pre-build islands

4 participants