Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
优化css交付—不在codeigniter php中加载css文件_Php_Codeigniter - Fatal编程技术网

优化css交付—不在codeigniter php中加载css文件

优化css交付—不在codeigniter php中加载css文件,php,codeigniter,Php,Codeigniter,在pagespeed insights中优化css交付,不加载css文件。 我曾尝试使用jquery加载css文件,但问题是css没有加载 我的代码: <script type="text/javascript"> $(document).ready(function(){ if($(".bs-example").size()>0){ if (document.createStyleSheet){ document.createStyl

在pagespeed insights中优化css交付,不加载css文件。 我曾尝试使用jquery加载css文件,但问题是css没有加载

我的代码:

<script type="text/javascript">
$(document).ready(function(){

if($(".bs-example").size()>0){
        if (document.createStyleSheet){
            document.createStyleSheet('<?php echo base_url();?>theme/css/style.css');
        }
        else {
            $("head").append($("<link rel='stylesheet' href='<?php echo base_url();?>theme/css/style.css' type='text/css' media='screen' />"));
        }
    }
});

$(文档).ready(函数(){
如果($(“.bs示例”).size()>0){
if(document.createStyleSheet){
document.createStyleSheet('theme/css/style.css');
}
否则{

$(“head”).append($(“CSS资产应包含在带有
标记的HTML标题文档中

而JS资产(包括JQuery就绪函数)应该位于
结束标记之后

<!DOCTYPE html>
<html>
<head>
    <title>Website</title>
    <link rel="path/to/css/file"/>
    <style>
        /*your custom CSS*/
    </style>
</head>
<body>
    HTML Body
</body>
<script src="https://code.jquery.com/jquery-3.2.1.js"/>
<script>
$(document).ready(function(){
    /*code*/
});
</script>
</html>

网站
/*您的自定义CSS*/
HTML正文
$(文档).ready(函数(){
/*代码*/
});

这样,CSS将首先被交付,JQuery Ready函数只有在检测到页面DOM已全部加载并且可以安全地运行.JQuery Ready函数中的JavaScript后才会执行。

CSS资产应包含在带有
标记的HTML头文档中

而JS资产(包括JQuery就绪函数)应该位于
结束标记之后

<!DOCTYPE html>
<html>
<head>
    <title>Website</title>
    <link rel="path/to/css/file"/>
    <style>
        /*your custom CSS*/
    </style>
</head>
<body>
    HTML Body
</body>
<script src="https://code.jquery.com/jquery-3.2.1.js"/>
<script>
$(document).ready(function(){
    /*code*/
});
</script>
</html>

网站
/*您的自定义CSS*/
HTML正文
$(文档).ready(函数(){
/*代码*/
});

这样,CSS将首先交付,JQuery Ready函数只有在检测到页面DOM已全部加载并且可以安全地运行.JQuery Ready函数中的JavaScript后才会执行。

您是否在config.php中设置了基本url?不要将其留空。
$config['base\u url'] = 'http://localhost/yourproject/“;
@wolfgang1983是的,我在我的配置文件中设置了:$config['base\u url']=''您在config.php中设置了您的基本url吗?请不要将其留空。
$config['base\u url']='http://localhost/yourproject/“;
@wolfgang1983是的,我在配置文件中设置了:$config['base\u url']=''仅在头文件中添加的Css链接仅在头文件中添加的Css链接