HTML: <link rel="stylesheet" href="compress_css.php" type="text/css"> PHP: compress_css.php header('Content-type: text/css'); ob_start("compress"); function compress($buffer) { /* Удаляем комментарии */ $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); /* Удаляем табуляции, пробелы, переводы строки и так далее */ $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); return $buffer; } /* Список CSS файлов */ include('master.css'); include('typography.css'); include('grid.css'); include('print.css'); include('handheld.css'); ob_end_flush(); 

What do you think about my idea? Will all browsers work? (I tested it on my slipper, through the Opera browser it works)

    3 answers 3

    Will all browsers work?

    You are processing on the server. There is no reason why for one browser it will be performed differently than for another.

    What say about my venture?

    What can I say about (no dash) about my idea and .

    I will say that this is a bicycle, for minification it is worth using a yui compressor and analogs, for assembling styles - either a gulp type assembler or, even better, a preprocessor - LESS, Stylus, SASS. And that really thoughtless replacement of all spaces will lead to errors in the verbose rules, not to mention the banal font-family: 'Courier New'; Dies safely.

    • The question of the profitability of the idea, and not how the provided script will work. - user31688
    • @TheDoctor is unprofitable, because debag will take six months, and then another yui compressor will be on hand. - etki
    • @Etki, there are two branches of thought here - the return of styles through php and compression of them. About the first you did not write anything, but in vain - I am also interested in the opinion. But I completely agree with the second one. - user31688
    • @TheDoctor, well, in the first case there will be an inferior sass clone. I do not see the point of distributing different styles for different pages, it goes against accepted caching practices, when exactly one file is given exactly once. - etki
    • @Etki, well, why is there no point - in one line you can get different combinations of styles, depending on the admin’s request, for example. You can divide a huge file into a bunch of smaller files, such modules. Etc. Use ideas, if you think and turn on the fantasy, it will come out a lot! :) - user31688

    I also have finite styles going through PHP.
    Although a couple of orders of magnitude more difficult, but it seems to me very convenient - I connect a bunch of styles in one line, I control access, I add "behind the screen", etc ...

      The idea is good, but how this style will be handled: border: 1px solid #999; or this: margin: 5px auto 15px auto;

      I answer: everything will float.

      • I wonder why? - user31688
      • one
        @densmith, because after minifying the code with your function, you get the following: border:1pxsolid#999 , instead of border: 1px solid #999 . This is incorrect css . See for yourself: jsfiddle.net/q2oy1gpm - VenZell
      • Yes Yeperny theater, the question is not the validity of the regular season, but the expediency of the idea! - user31688
      • I seem to have answered the question of expediency: if you turn on one or another selector depending on the situation, then yes, but minification through a regular schedule is a dangerous undertaking, you can produce bugs, etc. - densmith