-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minification #355
Minification #355
Conversation
Only for *.js files (except *-min.js), not when evaluate=true Also adds .gitignore entry for *-min.js files
Minifies javascript files using terser: https://github.com/terser/terser All storage files with a "*.js" url are minified, except when - evaluate=true - filename already ends in "-min.js" - storage already lists a corresponding "-min.js" file
Not sure why, but otherwise Stuff Breaks :-(
Removing comments would already help a lot for my code :) |
Thanks! Yeah, I was wondering about this. I reckon probably the most sensible thing to do is to use the existing Espruino tools for minification: https://github.com/espruino/EspruinoTools Main reason is there have been questions about stuff like including custom fonts and modules, which would get done automatically. Also pretokenisation would compress the files down even further. So then the question is really: do we just use the tools online, or do something offline? If we did it online then we could still allow folks to test their apps really easily using GitHub pages... |
Using existing Espruino tools does look like the best solution yeah, I noticed it even has different minification tools to pick from :-) Online would be nice for testing, but re-minifying the code for everybody every time they just want to install an app doesn't feel optimal. Also, while developing an app you probably don't want it minimized all the time, because debug output gets a lot less useful. How about something like
How are custom fonts and modules supposed to work? You |
Well, I'd decided to have a go at this - I'd been planning it for a while. Branch here: https://github.com/espruino/BangleApps/compare/minify_online Apart from the big blob of JS for EspruinoTools it seems pretty tidy. Give it a try - I think you'll find it's quick enough that you wouldn't really notice anything different. But are you say it'd be good to have a toggle for whether minification was applied or not. What I'm concerned about with the offline minification is for non-Node.js users they're basically not going to test with minified code at all because it's a bit of a steep learning curve on top of developing an app.
Yep, that's right. I think right now it's better to just include them. |
I gave it a try, and it was indeed fast enough to hardly notice. Seems it breaks the |
Can you try now? It might just be an issue with the tokeniser I was using |
Still broken. When I stick in (And if go to the app code and replace all |
Thanks for tracking that down! I just had a quick look to see if we could configure it in the minifier (esmangle), and I'm not sure we can (short of actually modifying the source). Not sure whether another minifier might be better? While I can and should fix that in Bangle.js firmware that doesn't help people who already have the old firmware, for which minified stuff will fail silently :( Any thoughts? The simple one I guess is just to manually plough through apps and change the |
for now, one option is just to remove minification and use pretokenization |
Can we not just turn off variable name mangling? Looks like there is a
You mean implement
I don't know, that seems like something we're going to regret. And I think it would also mean banning it's use in all new apps, along with having to explain this issue almost every time a new author submits something. |
Probably, yes. But then I wonder if there's much point doing it? Pretokenisation removes all whitespace anyway...
Yes. I guess we could detect when Yeah, changing all the apps right now would be a pain. It would solve the problem though ;) |
I think some minimizers can also do clever inlining of functions. |
I've just merged the pretokenisation branch, with a setting for turning it on and off. Closing this for now then... Maybe later when I sort out the let/const issue we can have a toggle for minification |
See #3
Not sure if this is the best way to go about it, but I figured I'd give it a shot:
bin/minify.js
script to minify*.js
files-min.js
version of files existshttps://github.com/terser/terser looked like a nice minifier
So if you don't run the minifier, the impact is that the uploader does a bunch of failed requests before falling back to uploading the not-minified version of files.
-min.js
files are ignored and not added to the repo. Not sure if there should be apackage.json
script
entry to run this, or some other build process?What worries me a bit is that having the minifier mangle names seems to result in broken code, and I'm not sure why. I suspect it might have something to do with
const
andlet
being treated asvar
, so actual scopes mismatch expectations?With mangling off it seems to reduce sizes by about 30-50% although it varies quite a bit (and e.g. image strings don't really compress)