4

YUI Compressor and other minifiers tend to remove unnecessary whitespaces, causing long lines. Safari 5 seems to fail rendering some rules from the css files when the file has more than 5000 characters per line (blog post about my experiences).

UglifyJS has a --max-line-len (default 32K characters) and the author says at the page

I’ve seen both FF and Chrome croak when all the code was on a single line of around 670K

What is the maximum safe line length in css files? I would like to support most of the still active browsers, while still removing unnecessary whitespaces. Any references to specifications would be useful.

1
  • 1
    I know this is not the question you asked but have you considered SASS/LESS? Additionally to hit the limit is a heck load of code is this well optimized without YUI? for example if you have .bank{background:#000000;} and .ted{background:#000000;} this could be made into .bank,.ted{background:#000;}. As YUI compressor only removes white space and doesn't make the code optimized. Though sounds like a load of code to optimise :P Apr 26, 2013 at 12:00

1 Answer 1

1

To quote the Closure Compiler FAQ:

The Closure Compiler intentionally adds line breaks every 500 characters or so. Firewalls and proxies sometimes corrupt or ignore large JavaScript files with very long lines. Adding line breaks every 500 characters prevents this problem. Removing the line breaks has no effect on a script's semantics. The impact on code size is small, and the Compiler optimizes line break placement so that the code size penalty is even smaller when files are gzipped.

jQuery (1.7.2) has a 32k single line limit. Since jQuery is a widely used library, I would use the 32k character limit as a guideline.

2
  • 500 characters is also a good limit for text editors (on the rare occasions you need to open a minified file). Jun 1, 2013 at 16:49
  • 4
    but he asked about CSS not JS
    – Lior
    Mar 20, 2014 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.