0

Say you have a css files loader style.php:

     <?php 
           header('Content-type: text/css'); 
           foreach(array('style1.css', 'style2.css', 'style3.css') as $f)
                 echo file_get_contents($f)
     ?>

Style1.css has 12KB, style2.css is 400kgs, and in the red corner obese style3.css weighting 800LBs is world champion at static resource bandwidth consumption!

I'm using style.php to combine the three files and send them to the client. I'm also using similar php files to send out JS resources, combined.

Is there some htaccess rule that I can tell to combine several static resources into a big one, and send that on-the-fly?

/EDIT:

This type of job CAN be handled by htaccess I'm sure I've read somewhere about server files included or something like that but I don't remember where. And I've also seen free hosting services that put a custom header or banner regardless of what files you host there.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
Silviu-Marian
  • 10,565
  • 6
  • 50
  • 72

2 Answers2

0

Well this type of job (combining css files) cannot be handled by .htaccess. You can at best use mod_deflate to compress the css file's contents.

However in PHP code you can combine and compress various CSS files. Take a look at third method in http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php

Finally take a look at minify here: http://www.minifycss.com/minify-tools/minify-css-tools.php

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • It doesn't help. The point here is to lower load for high volume traffic, while maintaining file structure for pain-free development. I've updated the question – Silviu-Marian Apr 16 '12 at 13:46
  • `It doesn't help`: Can u pls tell out of the 3 ways in my answer which doesn't help? – anubhava Apr 16 '12 at 13:51
  • First two impose additional requests for each of the three CSS files. On tiny javascript files, additional HTTP overhead is greater than filesize itself. Third method buffers files into memory which is exactly what I'm trying to avoid. – Silviu-Marian Apr 16 '12 at 14:02
  • Not sure exactly what you mean by `additional requests` here. Both mod_deflate and PHP code will do some minimal server side processing to compress your css/js. If you're doing it in PHP then of course you can check for a minimum file size and decide whether to serve the file(s) "as is" or to compress/combine. – anubhava Apr 16 '12 at 14:10
  • When you have 28 JS files and need to upload a critical update to the application, and after 10 minutes another update to update the previous update, 4 or 5 users will be bouncing because all the files need to be minified. When it can only be 1 user waiting for just one file which minifies in a blink. And then, do a 28 times for 100 users and compare that with direct cached file access. This problem solves with Apache directives I'm just not sure what name that damn little thing has. – Silviu-Marian Apr 16 '12 at 14:39
  • `When you have 28 JS files and need to upload a critical update to the application, and after 10 minutes another update to update the previous update, 4 or 5 users will be bouncing because all the files need to be minified` I would first fix this mess before trying to find a Apache module :) – anubhava Apr 16 '12 at 16:20
  • It's `"an Apache module"` and it's not one. You're confusing mess with general application requirements and any programmer knows about server-side includes. – Silviu-Marian Apr 21 '12 at 14:53
  • `It's "an Apache module" and it's not one`: God knows what this sentence means :) SSI is a server side scripting language and of course you can use any other scripting language like PHP, Python etc to do the same. – anubhava Apr 21 '12 at 17:27
  • I can but it's not as fast when answering requests. Run unrolled loops yourself and you'll see. Also, that sentence means you should use `an` when succeeding words start with vowels (an asset, an apache module, an emerald, an issue, an owl, etc). `A` should precede words that start with consonants. – Silviu-Marian Apr 21 '12 at 23:20
0

Eventually found what I was looking for. The thing was called Server-Side Includes (SSI).

Silviu-Marian
  • 10,565
  • 6
  • 50
  • 72