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

Reduce compiled css file size #647

Merged
merged 26 commits into from
Dec 15, 2023
Merged

Conversation

crftwrk
Copy link
Member

@crftwrk crftwrk commented Dec 4, 2023

Had a look to the compiled CSS and file size is big, too big. It's overall 455kb which includes 200kb Bootstrap, 30kb theme and the rest is the WC part. This PR reduces compiled minified CSS to 275kb which is absolute ok compared to other themes.

Figured out that using @extend on forms and buttons is a bad idea, because they have all this disabled, focus, focus-within, isvalid, is-invalid etc. states. This states creates in combination with the very bad WC classes huge selector strings which are only visible if you check one of this states. We do not need this states here.

Where possible, I readded the filters, but they do not catch all forms and buttons. For the rest i created custom form, custom check/radio with only :focus state and custom buttons with only :hover state and assigned them to the WC classes. This custom components are built with Bootstrap variables. Values can be changed as usual in _bscore_variables.scss.

The SCSS looks ugly but works and reduces 180kb file size. Tested in on several live shops and works fine, already live on bootscore.me as well.

Test: Check forms, checks and radios in cart, checkout and dashboard. Not each file must be reviewed, viewing the frontend is enough.

PR will have a conflict with #635, but I can fix this later. This one here seems to more important for me.

@justinkruit think this is an serious issue, IYLIMI ;-)

ps. Using @extend on other elements like badges or alerts have no negative effect.

Copy link
Member

@justinkruit justinkruit left a comment

Choose a reason for hiding this comment

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

The colors of the Coupon input don't seem to match, and the box shadow misses the animation.

Current Docs
image image

Other than that I can't spot anything.

@crftwrk
Copy link
Member Author

crftwrk commented Dec 10, 2023

Thank you for pointing this out, it has been fixed a68442a. Please check the cart coupon input https://bootscore.me/cart/.

Copy link
Member

@justinkruit justinkruit left a comment

Choose a reason for hiding this comment

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

image

Just spotted that the disabled outline button is also different, WC is setting a background color. Tbh not really intrusive, unless we want to force the Bootstrap style on it completely. Up to you if we also want to change that.

@crftwrk
Copy link
Member Author

crftwrk commented Dec 10, 2023

Fixed 40761c4, please check the cart.

@justinkruit
Copy link
Member

It's overall 455kb which includes 200kb Bootstrap, 30kb theme and the rest is the WC part. This PR reduces compiled minified CSS to 275kb which is absolute ok compared to other themes.

Is this comparison with expanded style, or with compressed? Just wondering. Reference:

if ($is_environment_dev) {
$compiler->setSourceMap(Compiler::SOURCE_MAP_FILE);
$compiler->setSourceMapOptions([
'sourceMapURL' => site_url('', 'relative') . '/' . substr(str_replace(ABSPATH, '', $css_file), 0, - 3) . 'map',
'sourceMapBasepath' => substr(str_replace('\\', '/', ABSPATH), 0, - 1),
'sourceRoot' => site_url('', 'relative') . '/',
]);
$compiler->setOutputStyle(\ScssPhp\ScssPhp\OutputStyle::EXPANDED);
} else {
$compiler->setOutputStyle(\ScssPhp\ScssPhp\OutputStyle::COMPRESSED);
}

@crftwrk
Copy link
Member Author

crftwrk commented Dec 11, 2023

It's the compressed one.

Before After
before after

Pushed 2 more commits, one fixes the coupon bg in dark mode and the other one replaces the product comment jQuery checkbox with the new SCSS. I found no more bugs, seems to work well...

Copy link
Member

@justinkruit justinkruit left a comment

Choose a reason for hiding this comment

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

All seems well.

@justinkruit justinkruit merged commit be045c4 into main Dec 15, 2023
@justinkruit justinkruit deleted the Reduce-compiled-css-file-size branch December 15, 2023 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants