Minified CSS has line breaks #75

Closed
vijayaraghavanramanan opened this Issue Jan 6, 2017 · 14 comments

Projects

None yet

2 participants

@vijayaraghavanramanan

Hi Frank,

Not sure which version this happened but the minified css (both external and inline) have line breaks. Do you know how this may have happened? Has the minifier option changed?

@futtta
Owner
futtta commented Jan 6, 2017

nothing changed really, but e.g. "important comments" are left as is by the PHP YUI CSS optimizer, so ...

@vijayaraghavanramanan

Hi Frank,

My css doesn't have special comments but I still see line breaks.

There's a setting in minifiers and perhaps it's line breaks is default in some, so that old IEs which cannot parse very long lines can read them. I think the limit is large so removing line breaks makes more sense as default.

@futtta
Owner
futtta commented Jan 9, 2017 edited

well, normally AO (well php yui css min) does not leave line breaks (just checked my site, only linebreaks are in the legacy MS-specific inlined background-image stuff). can you share your URL so I can have a look at the goings-on in your CSS?

@vijayaraghavanramanan

Yeah, the site is www.concertedaction.com and the AO css file is: http://www.concertedaction.com/wp-content/cache/autoptimize/css/autoptimize_5a174eceff80afd5113b428efe60dfa4.css

I also use W3TC, and have switched off its HTML minification for test. When I enable it, it's the one minifying the inline css. (Also note: inline css provided in minifiers form by me).

@futtta
Owner
futtta commented Jan 9, 2017

Your AO CSS-file indeed does have the linebreaks which PHP YUI CSS would remove, so AO is using a non-default minifier. This can happen for 2 reasons:

  1. if you activated the legacy minifiers (see FAQ on how to do that)? OR
  2. AO detects that there already is a CSSmin class (loaded by another plugin, W3TC maybe) and hence does not load its own (php css yui)?
@vijayaraghavanramanan

Oh possible. W3 Total Cache was recently updated after a long long time and probably explains why I am seeing this new behaviour: dont remember it happening before. Will experiment by disabling it etc.

(Not using legacy minifiers, so that option isn't the case)

@vijayaraghavanramanan
vijayaraghavanramanan commented Jan 9, 2017 edited

That indeed seems to be the issue. Have disabled w3tc and the file has just one line!

You can check. Still disabled. (Clear the cache as the filename seems to be the same)

@futtta
Owner
futtta commented Jan 9, 2017

indeed. check if entirely disabling any/ all minify options in W3TC helps maybe?

@vijayaraghavanramanan

Just disabling minify in W3TC while keeping the plugin active doesn't resolve. The file has line breaks. You can check. (Headers in files show "powered by w3tc" or something similar).

@futtta
Owner
futtta commented Jan 9, 2017

darn .. nothing AO can do here I'm afraid; W3TC should simply not instantiate a CSSmin if minification is disabled. you could add some code hooking into AO's API (using autoptimize_css_after_minify filter) to remove linebreaks (or switch page caching plugin)?

@vijayaraghavanramanan

What code should I add? Any reference?

W3TC is a nice plugin despite its various shortcomings. I can anyway live with those linebreaks. I use a github fix of the plugin and the developers there are quite fast in fixing. This thread might get referred when I raise an issue there.

@futtta
Owner
futtta commented Jan 9, 2017

well, the code here removes important comments in the optimized JS. you would need something similar (probably simpler as you only need to remove the linebrakes) for CSS.

@vijayaraghavanramanan

Thanks. Can manage. Good coding exercise for me :-)

@futtta
Owner
futtta commented Jan 9, 2017

have fun! :)

going to close this ticket here, as not to AO as such.

@futtta futtta closed this Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment