-
Notifications
You must be signed in to change notification settings - Fork 334
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
Update mangling of our classes names for our minified files #4076
Comments
The spike-mangle-options branch adds a Here is the result of a few options for that TL;DR:
@alphagov/design-system-developers, would there be any opposition to:
Baseline: reserved list of our component's classesSize: 35.34Kb (-18.30% from no mangling) Aggressive
|
@romaricpascal Thanks for this, no objections from me One I've considered in the past is targeting "private" class methods beginning with properties: {
regex: /^_/
} But savings are fairly negligible as you've shown |
Sounds sensible 👍🏻 We can always revisit later. Just to check, is the scope of this limited to Minification is otherwise in the hands of the service teams if they're importing individual our classes into their own JS? |
Cool, I'll enable the two options then 😊 And Ollie, yes, this is only for us generating |
This'll keep the names of our classes and functions intact for neater stacktraces. The [impact on file size](https://github.com/alphagov/govuk-frontend/issues/4076\#issuecomment-1677677788) is very acceptable in front of the maintainability gain.
This'll keep the names of our classes and functions intact for neater stacktraces. The [impact on file size](https://github.com/alphagov/govuk-frontend/issues/4076\#issuecomment-1677677788) is very acceptable in front of the maintainability gain.
This'll keep the names of our classes and functions intact for neater stacktraces. The [impact on file size](https://github.com/alphagov/govuk-frontend/issues/4076\#issuecomment-1677677788) is very acceptable in front of the maintainability gain.
This'll keep the names of our classes and functions intact for neater stacktraces. The [impact on file size](https://github.com/alphagov/govuk-frontend/issues/4076\#issuecomment-1677677788) is very acceptable in front of the maintainability gain.
This'll keep the names of our classes and functions intact for neater stacktraces. The [impact on file size](https://github.com/alphagov/govuk-frontend/issues/4076\#issuecomment-1677677788) is very acceptable in front of the maintainability gain.
What
Update the mangling of our class names for our minified files, as we may want to protect a few extra names than we do at the moment.
Before simply expanding the list of names we protect from mangling, I'd like us to quickly explore other mangling options from terser (a plain
false
,keep_classnames
,keep_fnames
, especially) and assess their impact on file size as we may gain in maintainability by not having to hand-maintain a list of names.Why
Terser's mangling provides further code minification by reducing long symbol names to single letters. This is great, but can make stack traces poorly readable. In the following screenshot, the stacktract lists
n
,o
anda
steps in the stacktrace, which users will struggle to reconciliate with ourGOVUKFrontendError
,SupportError
andGOVUKFrontendComponent
.Sourcemaps link users to the right place, but that requires them to take action and click on each entry of the stacktrace.
In v4, the names of our classes were protected because they were attached to the
window.GOVUKFrontend
object:This is no longer the case in v5, as we're shipping ESModules. With mangling enabled without reservations, we'd
export {h as Accordion/*...*/}
which would make errors thrown by theAccordion
show an entry forh
in the stacktrace (despite the named export). This is why we're currently protecting the names of our components from mangling (which enables the screenshot above to show a niceAccordion
).As we grow our codebase, add base classes and errors, potentially other new classes, it'll become more and more complex to track what to mangle and what not, so I'd like us to discuss revisiting what we mangle to make things more maintainable in the long run (at the price of a potential few extra bytes in the code).
Who needs to work on this
Developers
Who needs to review this
Developers
Done when
The text was updated successfully, but these errors were encountered: