Skip to content
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

USWDS - Core: Remove commented code from utility builder #5209

Merged

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Mar 29, 2023

Summary

Reduce size of compiled CSS when comments aren't explicitly excluded.

Problem statement

When compiling USWDS without optimization configured to remove comments, the output includes 1500 instances of the following snippet of code (one for each utility class):

/*
@if map-deep-get($utility, settings, responsive) {
  @include render-media-queries(
    $utility,
    $selector,
    $property,
    $value,
    $val-props
  );
}
*/

This unnecessarily inflates the size of the compiled output, and may cause extra work for the compilation itself.

Solution

Remove unused code.

Testing and review

mkdir tmp-uswds
cd tmp-uswds
npm init -y
npm i @uswds/uswds
brew install sass/sass/sass
echo "@forward 'uswds'; @use 'uswds-core' as *;" > styles.scss
sass --load-path=node_modules/@uswds/uswds/packages styles.scss | wc -c

Before: 1336223 bytes (1336.2kb)
After: 657293 bytes (657.3kb)
Diff: 678930 bytes (-50.8%)

Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to remove them if we're not using. Thanks!

Copy link
Contributor

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels safe to remove. The render-media-queries mixin no longer exists in the code base, and this code block was commented out 3 years ago.

Copy link
Contributor

@mahoneycm mahoneycm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw a major reduction in the file size of the project 👍

Copy link
Member

@thisisdano thisisdano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little change, big effect

@thisisdano thisisdano merged commit e3c7004 into uswds:develop May 8, 2023
@amyleadem amyleadem mentioned this pull request Jun 7, 2023
@aduth aduth deleted the aduth-rm-commented-utility-builder-code branch August 29, 2023 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants