css minification

via Digitalmars-d digitalmars-d at puremagic.com
Sat Jan 17 08:44:40 PST 2015


On Friday, 16 January 2015 at 22:32:07 UTC, Steven Schveighoffer 
wrote:
> On 1/16/15 5:23 PM, Andrei Alexandrescu wrote:
>> On 1/16/15 1:44 PM, Steven Schveighoffer wrote:
>>> On an embedded product we have with a dead-simple web server, 
>>> there is
>>> terrible network performance. Adding gzip support saved way 
>>> more than
>>> minification ever could. But the best performance improvement 
>>> was to add
>>> caching support to the server. Both the browser and the 
>>> server have to
>>> cooperate there.
>>
>> Pretty cool. The problem I'm having right now is the following 
>> pattern:
>>
>> 1. I have a mini-idea that takes me minutes to implement and 
>> turns the
>> ratchet in the right direction.
>
> At the cost of adding dependencies for builds, and requiring 
> builds be done with Internet access. I don't think it's out of 
> line to ask that if we are going to add extra build 
> requirements, we should make sure it's really making decent 
> progress.
>

Why do we need an external services?

     cat style.css |
         tr '\n' ' ' |
         sed 's/\/\*[^*]*\*\///g' |
         sed 's/\s\+/ /g' |
         sed 's/ \?\([(){},;]\) \?/\1/g

Strictly speaking, this is overzealous (e.g. it also operates 
inside strings), and I didn't even test it, but it will probably 
work for almost all cases. The current main CSS file of dlang.org 
(style.css) shrinks from 14757 to 11720 bytes, a reduction of 
~21%.

But even writing a compressor in D should be trivial, as you'd 
only need a lexer.

>> 2. I post it here in the hope that others will build upon or 
>> come with
>> better ideas.
>>
>> 3. I get feedback here that essentially demonstrates me that 
>> if I spent
>> some hours or days on a small research project on a better 
>> idea, it
>> would yield better results.
>
> I think you misunderstand. We are not saying "do a research 
> project", it takes seconds to gzip 2 files (the minified and 
> not minified) and see the size difference. If it's 
> super-significant, let's go for it! If you send me the minified 
> file, I can test it for you.
>
> There doesn't need to be any research, but all the suggestions 
> that have been provided have NOT required extra tools or 
> dependencies. That is a significant difference.
>
> -Steve



More information about the Digitalmars-d mailing list