I'm re-writing a website that will support multiple skins. Currently, I'm just planning on allowing images and CSS to be modified, but the underlying HTML will not change. And if the skin does not modify an image or CSS file, it inherits that file from the base skin.
With that in mind, here are the 3 ways I've considered so far for serving up skin-dependent files:
- Wrap all skin-specific requests requests in the view with a lookup function, ie:
<img src="<?php get_skin_file('/images/header.png', 'skin1'); ?>" /> function get_skin_file($file, $skin) { $skin_file = '/' . $skin . '/' . $file; if(is_readable($skin_file)) return $skin_file; return '/default/' . $file; }
Have php serve the image
<img src="/header.png.php?skin=skin1" />
Always attempt to load the skin file and if it doesn't exist, use ModRewrite to send the result to a php handler script:
<img src="/skin1/header.png" />
Number 2 is what I'd like to do, but I'm just concerned with the performance implications of having PHP serve up basically every image file.
My userbase is small enough (about 30k users) that I don't think it'd really be an issue, but I'd also just like to learn what other folks do in this situation.
Thanks.
EDIT: I have no idea why my code is not formatted properly. I hit the code button and checked that it's 4 spaces, but it's still ugly. Sorry about that.