schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs and SSR.
https://jasprpad.schultek.de
MIT License
1k stars 59 forks source link

feat: Minify javascript in jaspr build step #193

Closed walsha2 closed 3 months ago

walsha2 commented 3 months ago

Description

@schultek It looks like there is some considerable savings that can be made by simply minifying the resulting, compiled, JS files from dart2js. This would reduce the time taken to render an SSR app as this, rather large, un-minified JS is being sent by the server, namely app.client.dart.js

The following were generated using jaspr build (Jaspr CLI (Version 0.10.0)) for a relatively small app with just a couple screens.

Before Minification

968K    build/jaspr/web/main.clients.dart.js
468K    build/jaspr/web/main.clients.dart.js_1.part.js
1.4M    build/jaspr/web/components/app.client.dart.js

After Minification

584K    build/jaspr/web/main.clients.dart.js
292K    build/jaspr/web/main.clients.dart.js_1.part.js
852K    build/jaspr/web/components/app.client.dart.js

Additional Context

https://dart.dev/tools/webdev#build

I was under the assumption that webdev build and/or dart2js would minify the JS by default, no? Not sure why that is not happening here or if the option is not enabled.

packages/jaspr_cli/lib/src/commands/build_command.dart

Related

Maybe even something to minify the CSS? Although I understand if this should be an outside tool and up to the user.

schultek commented 3 months ago

Yes there is an option for dart2js to optimize the generated js, specifically there are four levels of optimization.

It makes sense to expose this as an option to jaspr build as well as pick a reasonable default

schultek commented 3 months ago

This is a good issue for a first contribution if you like 😁✌️