php-autoprefixer icon indicating copy to clipboard operation
php-autoprefixer copied to clipboard

Some more optimization

Open kubiqsk opened this issue 4 years ago • 5 comments

I see that you remove zero (0) when it's in expression 0.5px or calc(-0.5em + 10%) etc. which is great and I really love it as it makes final CSS smaller.

What about another optimization? Remove unnecessary quotes? Currently I use this to remove them:

$prefixed_css = str_replace(
	array(
		'[role="button"]',
		'[type="button"]',
		'[type="reset"]',
		'[type="submit"]',
		'[type="search"]',
		'[type="file"]',
		'[type="checkbox"]',
		'[type="radio"]',
		'="top"',
		'="right"',
		'="bottom"',
		'="left"',
	),
	array(
		'[role=button]',
		'[type=button]',
		'[type=reset]',
		'[type=submit]',
		'[type=search]',
		'[type=file]',
		'[type=checkbox]',
		'[type=radio]',
		'=top',
		'=right',
		'=bottom',
		'=left',
	),
	$prefixed_css
);

kubiqsk avatar Sep 17 '21 12:09 kubiqsk

I am not sure that is css attribute selector without quote can support all browser, so i can not change it

padaliyajay avatar Sep 17 '21 12:09 padaliyajay

No one is using without quote https://www.w3schools.com/css/css_attribute_selectors.asp

padaliyajay avatar Sep 17 '21 12:09 padaliyajay

You can be sure ;) it works if it's just 1 string matching regex [a-zA-Z0-9_]+ You can read about it here: https://www.w3.org/TR/CSS21/grammar.html#grammar

kubiqsk avatar Sep 17 '21 12:09 kubiqsk

w3schools just shows you best practices when you're learning CSS... yes it's good idea to use quotes when you are a beginner

but when you want to compile most optimized CSS and get best results, then it's a good idea to get rid of all unnecessary characters in it... this means leading zeros in decimal numbers - like you already did, but also unnecessary quotes...

but sure, it's up to you ;) I'm just offering you a better results when we're talking about final file size

kubiqsk avatar Sep 17 '21 12:09 kubiqsk

PHP-CSS-Parser is behind this autoprefixer, so this can only be fix by that library. ask them if they can help on this https://github.com/sabberworm/PHP-CSS-Parser

padaliyajay avatar Sep 17 '21 12:09 padaliyajay