Note that there are some explanatory texts on larger screens.

plurals
  1. POServing php as css/js: Is it fast enough? What drawbacks are there?
    primarykey
    data
    text
    <p>I've recently started getting into the area of optimizing preformance and load times client side, compressing css/js, gzipping, paying attention to YSlow, etc.</p> <p>I'm wondering, while trying to achieve all these micro-optimizations, what are the pros and cons of serving php files as css or javascript?</p> <p>I'm not entirely sure where the bottleneck is, if there is one. I would assume that between an identical css and php file, the "pure" css file would be slightly faster simply because it doesn't need to parse php code. However, in a php file you can have more control over headers which may be more important(?).</p> <p>Currently I'm doing a <code>filemtime()</code> check on a "trigger" file, and with some php voodoo writing a single compressed css file from it, combined with several other files in a defined group. This creates a file like <code>css/groupname/301469778.css</code>, which the php template catches and updates the html tags with the new file name. It seemed like the safest method, but I don't really like the server cache getting filled up with junk css files after several edits. I also don't bother doing this for small "helper" css files that are only loaded for certain pages.</p> <ul> <li>If 99% of my output is generated by php anyways, what's the harm (if any) by using php to directly output css/js content? (assuming there are no php errors)</li> <li>If using php, is it a good idea to <code>mod_rewrite</code> the files to use the css/js extension for any edge cases of browser misinterpretation? Can't hurt? Not needed?</li> <li>Are there any separate guidelines/methods for css and javascript? I would assume that they would be equal.</li> <li>Which is faster: A single css file with several <code>@imports</code>, or a php file with several <code>readfile()</code> calls?</li> <li>What other ways does using php affect speed?</li> <li>Once the file is cached in the browser, does it make a difference anymore?</li> </ul> <p>I would prefer to use php with .htaccess because it is much simpler, but in the end I will use whatever method is best.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload