简体   繁体   中英

Is it a bad idea to use a php css file?

I just want to know if it's a good or bad idea to use a php css file performance wise. I really want to do a php method for the use of variables.

By php css file I mean:

<?php header("Content-type: text/css"); ?>

What are your thoughts on this?

Nope, it's fairly common in the wild. The only performance hit is when you output the file dynamically, which can be mitigated easily with server-side (and client side) caching.

This is a bad idea, but only if you don't cache.

On the server side, I expect that you're using some sort of global site-level variables, then building your CSS from that. Fine, just make sure that you save the file, invalidating it whenever it needs to change (say, from an SVN checkin).

From the client's perspective, you want to ensure that it doesn't have to download it on every page load. For that you'll need to properly set last-modified headers or an Etag.

I don't think it's a bad idea, and I'm currently doing it in that way. In my framework I dynamically concatenate two css groups in two separate files, the site main CSSs (layout, forms, etc) and some module specific ones if they exists. So, they can be cached separately. I also include some dynamic path inside using php vars.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM