开发者

Caching stylesheets with $_GET data attached

I'm in the process of opt开发者_如何学Goimizing CMS website's CSS usage and I decided it would be a good idea to serve the CSS through PHP so I could send the ID of the current page to the stylesheet, e.g:

<link href="/css/style.php?id=<?php echo $page_id; ?>" type="text/css" rel="stylesheet" />

I did this because I thought it would be a good way to stop CSS meant for different pages being loaded on pages that didn't need it. Then today it struck me, this setup means when a new user clicks an internal link, they won't be able to use their cached stylesheet and will have to download a new stylesheet for every page.

Obviously this isn't the way forward, does anybody know a better way of doing it? I've considered using session data, but I'd rather not because if anybody had cookies off it would break. I've also considered using $_SERVER['REQUEST_URI'] in the stylesheet but I'm worried about false positives.

Any ideas would be appreciated. Thanks!


I am pretty sure that caching is always better then serving up dynamic spreadsheets.

The bottleneck in pretty much every webapp is bandwith/latency. So not having to request a file is better then serving a lot of perhaps smaller files that may require a bit less processing power.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜