dtg25862 2019-03-29 17:24
浏览 92

结合外部php文件中的css文件不起作用

I'm trying to place a bunch of css files into an external file in order to improve the page loading speed. I don't get any errors but the layout of the page is corrupted due to the missing css. Here is what I am doing. Given this in the page header

    <link rel="stylesheet" type="text/css" href="ext/css/template.css" />
    <link rel="stylesheet" type="text/css" href="ext/css/tabcontent.css" />

I replace it with

    <link rel="stylesheet" type="text/css" href="ext/css_loader.php" />

and the css_loader.php file has the following code:

    <?php
    $css = array(
    'ext/css/template.css',
    'ext/css/tabcontent.css'
    );

    $mergeCSS = "";
    foreach ($css as $css_file) { $mergeCSS .= file_get_contents($css_file); }
    ob_start('ob_gzhandler');
    header('Content-type: text/css');
    header('Vary: Accept-Encoding');
    echo ($mergeCSS);

I did the same for the javascript files and it worked correctly. If I display the loaded css, it appears to be there, though it is all one big block.

Is it possible to do this with css files? If so, can someone explain why it is not working?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用