-
Notifications
You must be signed in to change notification settings - Fork 446
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
"Extend > Reducing CSS Size". Not always the case. #177
Comments
Well, the example is not valid since the compared results are not equivalent CSS styles. Besides, the docs never say:
The statement there is:
that's it. And the valid example of the
vs.:
These snippets are equivalent and the mixin variant produces more compact output (and to be honest, this is supposed to be quite self-evident stuff).
It's just the same story as with your example. Expanding Bootstrap Either way, what is your suggestion? I can't see any issue. |
@seven-phases-max: thanks for the feedback. You are correct about my examples not being valid. Sorry, my bad. Just to provide an example (pretty similar to the one you provided)
vs
In the above example, as in yours, the output of the mixin version (224 chars) is shorter than the one using extends (238 chars). Just a mere 5.88% shorter. But that percentage start to grow quickly if the selector strings are larger.
vs
Bottom line: my suggestion? Not sure. As you said, a good blog post could help to clear out that using extend doesn't lead necessarily to shorter output, and that there are situations where using mixins could generate shorter output than using extends. |
@maniqui There is already a community agreed-upon solution for this. It just has yet to be implemented. It's in less/less.js#1155 but I've summarized it in a new issue because I think it's been forgotten: less/less.js#2101. So, to make
// Output:
.a,
.some-selector {
prop: value;
}
.a:hover,
.a:focus,
.some-selector:hover,
.some-selector:focus {
prop: value;
}
// .parent .a { } is ignored, as it's not an exact match Your scenario and comments are similar to ones made as the spec was being developed, but unfortunately, as I said, it hasn't landed in the parser yet. I'd put your two cents into less/less.js#2101 if you want to see this happen. I think the "deep" keyword would definitely be a common use case. |
So I'm tyrantely closing this (sort of "merging" to #138). Maybe... someday... we have a "Book" section in the docs where we share some articles for "best practices / design patterns" stuff. |
That seems more a blog / tutorial site. I would keep that separate. |
The exact www location is not important. There's no difference between http://lesscss.org/book and http://lessbook.org |
Sure there is: Pagerank of article pages, public perception, user psychology, etc. :-) I think if it's an official subset of lesscss.org (maintained by less-docs crew), I'd keep it on same domain for sure. If it's a spin-off site run by different people, then another domain makes sense. I would suggest /blog (or blog.lesscss.org) or /tutorials rather than /book, which sounds like a static (unchanging) eBook. |
Sure there's not - in context of this topic (or more specifically the reason I put for closing it).
This all is for less/less-meta#2 ;) P.S. Sorry if I sound harsh a bit, I don't intend to of course I'm more about being mildly sarcastic (so if there's any pun it's just my language skills). |
Haha right that. :-) |
Using the
:extend(.selector all)
pseudo-selector not always provides a shorter output (ie. smaller filesize), compared to the output generated when using the same selector (the one being:extend()ed
) as a mixin.Of course, this could be expected as using
:extend(.selector all)
is similar but not exactly the same to using a mixing.Why?
Because when using
:extend(.selector all)
, it even extends the selector when it's used in more complex selectors (for example, as a child, like in.parent .selector
).Using a mixin doesn't cover those cases.
A quick example:
Output length: 289 characters
Now, a similar use case, but using
.a
as a mixin.Output length: 242 characters
As you can see, the version using
:extend
is some bytes larger (and, let me state it again, it include some extra rules not present in the mixin output).In case you are looking for some real case examples, I suggest you to try extending and mixing in Bootstrap, using the classes
.btn
and.panel
, for example.Extending the
.btn
class will get you a far more larger output than using it as a mixin. Of course, when extending, there are more selectors "covered" than when mixin in.While doing the same for the
.panel
class leads to a shorter output when using:extend(.panel all)
than when using it as a .mixin.TL;DR: using
:extend()
usually leads to shorter CSS output, but that's not always the case.The text was updated successfully, but these errors were encountered: