-
Notifications
You must be signed in to change notification settings - Fork 3
Description
When you try to access a named property of an Object in JavaScript, either by subscripting (foo["bar"]) or by dot notation (foo.bar), you'll either get the value of the property, or undefined if the property doesn't exist - you don't get a KeyError or anything like that. If you were checking if a property was true or not, you'd get the same result whether it existed with a false value, or if it didn't exist at all. We can take advantage of this to eliminate some unnecessary properties in project.json.
In my testing, the block properties "inputs", "fields", "shadow", and "topLevel" can all be excluded if they have false/empty values. This can save up to 52 bytes per block (plus ~3 extra bytes for the commas and all that).
I tested it on Paper Minecraft, and made sure that it worked properly in both online and desktop Scratch after my optimizations - here were my results:
Before compression: 4,835,853 bytes (92.2%)
After compression with ProjectJsonMinimizerNew: 3,538,267 bytes (67.5%)
After further compression: 2,855,259 bytes (54.5%) (~20% further size reduction)
Obviously, the results would be even more dramatic on projects that are more code-heavy and less data-heavy.