Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
    
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 –  bybe Apr 26 '13 at 12:00
add comment

1 Answer

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.

share|improve this answer
    
500 characters is also a good limit for text editors (on the rare occasions you need to open a minified file). –  DisgruntledGoat Jun 1 '13 at 16:49
    
but he asked about CSS not JS –  Lior Mar 20 at 9:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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