M B Parvez
M B Parvez

Reputation: 816

Is there any pros. or cons. if I load CSS or Javascript into a PHP file?

I'm using multiple CSS file in a project and also using a Php file as "stylesheet" to load all the CSS into a single file with compress them all. For that I'm using the following code:

$cssFiles = array("reset.css", "main.css", "plugin.css");

$css = "";

foreach($cssFiles as $cssFile){
    $css .= file_get_contents($cssFile);
}

header("Content-type: text/css");

echo($css);

Now I need to know what is the advantages or disadvantages of this process?

I'm doing the same thing for javascript files too.

Thanks.

Upvotes: 0

Views: 269

Answers (2)

Edgar Orozco
Edgar Orozco

Reputation: 2782

Cons:

  • The processor will load the charge of the parsing, interpreting and finally output the CSS and JS process
  • Server Memory will load the same charge for this processes.

Pros: I Really found hard to think in any pro here... maybe the non use of other tools than PHP to implement dynamic CSS and JS?

Upvotes: 1

botero
botero

Reputation: 596

I would suggest instead of doing that using php, use grunt to combine them and minify them

This question explains better how you can do that:

How to concatenate and minify multiple CSS and JavaScript files with Grunt.js (0.3.x)

Upvotes: 1

Related Questions