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

Optimize generated CSS by removing unused selectors #2008

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

zecakeh
Copy link
Contributor

@zecakeh zecakeh commented Nov 20, 2024

This was done thanks to this Hugo guide.

The way this works is that Hugo generates stats about the HTML elements, IDs and classes that can be found in the website, and we post-process the generated CSS with PurgeCSS that uses those stats to remove unused selectors.

The generated file's size goes down from 403.8 Ko to 38.1 Ko (less than 10%!). Gzipped it goes down from 64.8 Ko to 8.7 Ko (less than 15%!). This huge gain is probably explained because Docsy includes the whole CSS from Bootstrap instead of only the parts that we need.

More than the gain in the download time of the file, we should gain performance in the parsing of the CSS.

Pull Request Checklist

Preview: https://pr2008--matrix-spec-previews.netlify.app

Hugo generates stats about the HTML elements, IDs and classes that can be found in the website,
and we post-process the rendered CSS with postcss-purgecss that uses those stats to remove unused selectors.

Signed-off-by: Kévin Commaille <[email protected]>
@zecakeh zecakeh requested a review from a team as a code owner November 20, 2024 10:56
Signed-off-by: Kévin Commaille <[email protected]>
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

LGTM

layouts/partials/head-css.html Outdated Show resolved Hide resolved
@richvdh richvdh enabled auto-merge (squash) December 10, 2024 22:54
@richvdh richvdh merged commit 1accb9e into matrix-org:main Dec 10, 2024
12 checks passed
@zecakeh zecakeh deleted the purge-css branch December 10, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants