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

Use important properties for optimalization opportunities #184

Closed
Venemo opened this issue Nov 20, 2013 · 11 comments
Closed

Use important properties for optimalization opportunities #184

Venemo opened this issue Nov 20, 2013 · 11 comments
Milestone

Comments

@Venemo
Copy link
Contributor

Venemo commented Nov 20, 2013

In cases where there are not enough non-important properties for compacting into a shorthand, but there could be when taking important properties into account, we can use them to our advantage.

For example, this code:

foo {
  margin-top: 1px;
  margin-right: 2px;
  margin-bottom: 3px !important;
  margin-left: 4px !important
}

is equivalent to the following:

foo {
  margin: 1px 2px 0 0;
  margin-bottom: 3px !important;
  margin-left: 4px !important
}

Reasoning:
In the example it is safe to add a fake 0 for non-important margin-bottom and margin-left because their values are going to be overridden by the important properties. However, there is a visible gain in terms of CSS size.

@Venemo
Copy link
Contributor Author

Venemo commented Nov 20, 2013

NOTE: I've already implemented this in my fork, just opened the ticket in order to make you aware of this possibility.

@GoalSmashers
Copy link
Contributor

👍 good stuff

@XhmikosR
Copy link
Contributor

I'm not sure this makes sense code-wise though. The resulting CSS might be smaller, sure, but it's like going forward and then changing direction to go backwards...

@Venemo
Copy link
Contributor Author

Venemo commented Nov 20, 2013

@XhmikosR Sorry, I don't quite get your point

@GoalSmashers
Copy link
Contributor

@XhmikosR I don't get it either - our goal is the smallest CSS possible no matter what, right?

@XhmikosR
Copy link
Contributor

I guess I was thinking it from a code quality point of view. It's a hack, but it should work, so ignore my previous comment.

@Venemo
Copy link
Contributor Author

Venemo commented Nov 21, 2013

@XhmikosR Did you actually read my code and think it's a hack? If so, I'm open to your suggestions on how to implement it differently.

@XhmikosR
Copy link
Contributor

I didn't read your code; I read the example above... It's a hack because you set one property to 0 knowing it will be overwritten anyway, that's what I meant.

I can't think of any other approach for this specific example, so your way seems to be the best at this point if we want to handle this case.

@GoalSmashers
Copy link
Contributor

@XhmikosR I believe there is no other way. We are fine as long as it renders the same way.

@XhmikosR
Copy link
Contributor

Yeah. I don't think there would be any issues with any browser. The last property is always used as far as I know.

@GoalSmashers
Copy link
Contributor

Fixed with #249.

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

No branches or pull requests

3 participants