If you have some JavaScript code, it goes through a few phases as it's evaluated by your browser:
1. Parsing
2. JIT optimizing
3. Compilation to bytecode
4. Re-optimization as the program runs
Steps 1 and 2 are expensive, and there are a few ways to cut down on them:
- Removing dead code before you ship
- Optimizing your code for the JIT compiler (eg. Closure Compiler does this)
- Webassembly
- Pre-evaluating your code with Prepack
More philosophically, the question is "when does my code run?". The answer has usually been "on the client". With Prepack, the answer is "as much as possible during compilation, and the remainder on the client".