Before you ship your code to production you may need to bundle your JS files to avoid serving too many files.
In this book we use esbuild - an extremely fast JS bundler used internally by Snowpack.
Add snowpack.config.js:
export default {
optimize: {
bundle: true,
minify: true,
target: 'es2015',
},
};
Time to build your project:
npm run build
esbuild will generate a build
directory with the optimized production code.
Verify your production distribution locally:
http-server build
We're using Netlify to host this project. In the following figure, you will find the deployment settings:
Once you connect your Github repo to Netlify configure:
- branch to deploy: we're using a branch called deploy. On main, there is a lightweight setup without a bundler.
- build command:
npm run build
from the previous step - publish directory:
build
a default esbuild directory
Every time you push to the branch, Netlify will deploy a new version.
You can find the latest deployed version here: https://hyperposts.netlify.app/
One of the most underrated performance optimizations is using lighter frameworks and libraries.
Use bundlephobia to check the size of your dependencies (minified+gzipped):
- https://bundlephobia.com/[email protected] (1.7kB)
- https://bundlephobia.com/[email protected] (1.6kB)
- https://bundlephobia.com/[email protected] (0.7kB)
- https://bundlephobia.com/[email protected] (3.9kB)
To make this comparison relevant here are some of the popular libraries:
- https://bundlephobia.com/result?p=@angular/[email protected] (90kB)
- https://bundlephobia.com/[email protected] (36kB)
- https://bundlephobia.com/[email protected] (22.8kB)
Using Hyperapp is a performance optimization in and of itself. In other words, with Hyperapp you're paying a much much lower performance tax than in Angular, React, or Vue. No matter how many performance optimizations you apply to them, they will never match the load time performance of unoptimized Hyperapp. And that's what we call a performance pit of success. Or a negligible performance tax.
The received wisdom that you need to choose between developer experience and load time performance becomes a false dichotomy. No matter what performance metric you choose be it FCP, LCP, TTI, FID, TBT you'll be fine. Even if you're scratching your head thinking: WTF are those metrics (WTF stands for "What's this for").
Check your application bundle size in the browser:
With minification and Brotli compression (from the Netlify server), the application is around 10kB. It easily fits into most real-world performance budgets. It means that Hyperapp is a great tool when you need to build apps for the network and CPU constrained devices, without sacrificing developer experience.