Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Last active March 28, 2026 15:38
Show Gist options
  • Select an option

  • Save Rich-Harris/d9de6692eaae94f8aa7ca87a0dc980f2 to your computer and use it in GitHub Desktop.

Select an option

Save Rich-Harris/d9de6692eaae94f8aa7ca87a0dc980f2 to your computer and use it in GitHub Desktop.

Revisions

  1. Rich-Harris revised this gist May 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion prepack-svelte.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ console.log("Hello carol!");

    ## What is Svelte?

    Svelte is a UI framework (like React or Vue), except that it's *actually* a compiler. It takes your UI templates and turns them into small, blazing fast components. In other words, rather than you providing new state and the framework doing an whole load of virtual DOM reconciliation to figure what changed, Svelte writes straightforward code that manipulates the DOM directly — for example, here's a snippet from the `<h1>Hello {{name}}!</h1>` [example](https://svelte.technology/repl?example=hello-world):
    Svelte is a UI framework (like React or Vue), except that it's *actually* a compiler. It takes your UI templates and turns them into small, blazing fast components. In other words, rather than you providing new state and the framework doing a whole load of virtual DOM reconciliation to figure what changed, Svelte writes straightforward code that manipulates the DOM directly — for example, here's a snippet from the `<h1>Hello {{name}}!</h1>` [example](https://svelte.technology/repl?example=hello-world):

    ```js
    // the update method is called whenever you set new state
  2. Rich-Harris revised this gist May 4, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion prepack-svelte.md
    Original file line number Diff line number Diff line change
    @@ -63,7 +63,7 @@ window.log = function () {
    };
    ```

    ...the 928 lines in fact become slightly *larger* (although the resulting code does appear to run slightly quicker).
    ...the 928 lines in fact become slightly *larger* (although the resulting code does appear to initialise slightly quicker, as we'd expect).

    In other words, while Prepack is magical, it isn't *magic* — it won't rewrite your app to make slow code run faster, it will only do initialisation work ahead of time.

  3. Rich-Harris created this gist May 4, 2017.
    75 changes: 75 additions & 0 deletions prepack-svelte.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    *Note: I'm not involved in Prepack in any way — please correct me if I say anything incorrect below!*

    A few people have asked me if [Prepack](https://prepack.io) and [Svelte](https://svelte.technology) are similar projects with similar goals. The answer is 'no, they're not', but let's take a moment to explore why.

    ## What is Prepack?

    Prepack describes itself as a 'partial evaluator for JavaScript'. What that means is that it will run your code in a specialised interpreter that, rather than having some effect on the world (like printing a message to the console), will *track the effects that would have happened* and express them more directly.

    So for example if you give it this code...

    ```js
    [ 'alice', 'bob', 'carol' ].forEach( function ( person ) {
    console.log( `Hello ${person}!` );
    });
    ```

    ...it will turn it into this:

    ```js
    console.log("Hello alice!");
    console.log("Hello bob!");
    console.log("Hello carol!");
    ```

    **That's amazing.** It's a mind-bending project with all sorts of ramifications that we probably haven't thought of yet.


    ## What is Svelte?

    Svelte is a UI framework (like React or Vue), except that it's *actually* a compiler. It takes your UI templates and turns them into small, blazing fast components. In other words, rather than you providing new state and the framework doing an whole load of virtual DOM reconciliation to figure what changed, Svelte writes straightforward code that manipulates the DOM directly — for example, here's a snippet from the `<h1>Hello {{name}}!</h1>` [example](https://svelte.technology/repl?example=hello-world):

    ```js
    // the update method is called whenever you set new state
    update: function ( changed, state ) {
    if ( text_1_value !== ( text_1_value = state.name ) ) {
    text_1.data = text_1_value;
    }
    }
    ```


    ## They sound quite similar!

    At a high level, they do have something in common — they're both taking work that used to happen *n* times in the browser, and doing it once at build time instead.

    But there is a crucial difference. Because Prepack is running your code, it only cares about what happens during initialisation. [Take this example](https://medium.com/@dtinth/wow-prepack-is-awesome-b3d802590c42) of what happens if you run Prepack on a 928 line Webpack bundle generated from the following code:

    ```js
    console.log(require('util').inspect({ hello: 'world!' }));
    ```

    It collapses those 928 lines into this:

    ```js
    console.log("{ hello: 'world!' }");
    ```

    That really is remarkable. But if instead of logging the output, we create a function to do the same — in other words, move the work from initialisation to later, when our app is already running...

    ```js
    window.log = function () {
    console.log(require('util').inspect({ hello: 'world!' }));
    };
    ```

    ...the 928 lines in fact become slightly *larger* (although the resulting code does appear to run slightly quicker).

    In other words, while Prepack is magical, it isn't *magic* — it won't rewrite your app to make slow code run faster, it will only do initialisation work ahead of time.


    ## What is Svelte doing differently?

    Svelte isn't *running* your code, it's *understanding* it. That's how it's able to write code that starts fast and stays fast.

    But Svelte is focused on doing one job — being a UI framework — whereas Prepack is a far more general purpose tool. The two projects occupy very different spaces, but are both part of a growing trend that's about moving work out of the browser and into servers and build processes. There's a huge amount of exploration still to do in this area, and for my money it's one of the more exciting topics in the JavaScript community at the moment.