-
Notifications
You must be signed in to change notification settings - Fork 93
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
Rewrite many selectors with :is()
to reduce size
#208
base: master
Are you sure you want to change the base?
Conversation
(Sorry for embarrassingly late replies, finally got a chance to get back to this project.) Hey, wow, this is very cool, thanks a lot!! I'll do a more thorough pass over the changes later to catch any suspicious differences, but overall the direction of the changes is great, and the size savings are amazing. Regarding performance, my wishful thinking would be that browsers either have an one-time preprocessing step to expand the On the other hand, given that GitHub (which is actually one of the lighter sites out there) takes several seconds to render any page and refuses to display 1000-line diffs "because it might slow down the browser", I think we're fine here 😆 In my experience, m.css pages of basically any length (say, this one or this) always rendered immediately on any browser I tried, without any visible pop-ins or relayouting and I can scroll through them without any stutter whatsoever. So even if this slowed them down 2x (which I seriously doubt) it'd be still an acceptable tradeoff for such massive size savings. |
Would you like me to rebase to resolve the conflict and change the target branch to |
Uh oh, did I cause a conflict with my recent CSS changes? Thought it would be fine, but apparently it clashed with your fixes to the Hmm, actually, I still need to think about browser compatibility. I didn't even adopt CSS grids (#31) yet for fear of cutting some users out (and I was even processing CSS variables and I don't want to just discard your changes or put them aside and let them rot, though. As a middle-ground solution I'm thinking I could update the |
Another option to consider instead of post-processing away all the Unfortunately, any kind of post-processing is going to be a bit beyond me, but do feel free to let me know if you need me to mess with this PR some more! For now, I imagine it'll stay on the back burner. |
I understand this is a major (unasked for) change, and I expect it needing a conversation to decide if it gets merged. To outline what this change means: the compiled output shrinks from 92.6kB -> 65.5kB uncompressed, and from 12.6kB -> 9.6kB gzipped. Using brotli and some further simple tweaks to the compiling process, I was able to get it down to 7.5kB.
I recommend looking at the changes one commit at a time, as some are less major than other. Each should work on its own, so if one commit seems particularly nasty it could be omitted. This PR does not include the changes for any compiled files, I figured those could be added when a final changeset is decided on.
This might somewhat impact compatibility depending on what browser share you're currently targeting. Can I Use estimates this change would work for about 90% of people.
Readability is another potential concern. I personally find it easier to read and understand selectors that use
:is()
when compared to long lists of repeated selectors, but if you disagree I imagine there's a comfortable middle-ground.Performance is perhaps my biggest concern, because I understand it the least. I don't know how to test this or what scale this change is on, but I imagine it would make applying the CSS slower to some extent.
As for whether this changes how any of the styles are applied, my tests seem to indicate no. I opened the site on various pages with the original and modified CSS and ran the code attached below. I then diffed the results for each page, and none of them had any differences. This does not test for states like
:hover
or similar, but by looking at the code and doing some quick manual checks I feel confident enough that they work as expected.