CSS和Boostrap CDN并未出现在所有页面上

时间:2016-01-20 21:46:41

标签: jquery css twitter-bootstrap cdn

我正在使用Node + Express + Handlebars构建应用程序。我将我的标题保留在部分布局中,它包含CSS,Bootstrap,jQuery等的所有CDN /引用。出于某种原因,并非所有页面都会加载各种引用和CDN。这是我的头文件:

  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="images/flame.png">
  <title>Metrics</title>
  <link href="css/art-fonts.css" rel="stylesheet">
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link href="css/art-fonts.css" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="css/custom.css">
  <link href="css/dashboard.css" rel="stylesheet">
  <script src="js/ie-emulation-modes-warning.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
  <nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a  href="agile1.html"> <img src="images/coolmetrics.png"  alt="CoolMetrics"/></a></div>
      <div id="navbar" class="navbar-collapse collapse">
        <form class="navbar-form navbar-right">
           <input type="text" class="form-control" placeholder="Search...">
        </form>
        <ul class="nav navbar-nav navbar-right">
          <li><a href="#">Dashboard</a></li>
          <li><a href="#">Settings</a></li>
          <li><a href="#">Profile</a></li>
          <li><a href="#">Help</a></li>
        </ul>
      </div>
    </div>
  </nav>
  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-md-2 sidebar">
        <ul class="nav nav-sidebar">
          <li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>
          <li><a href="#">Reports</a></li>
          <li><a href="#">Analytics</a></li>
          <li><a href="#">Export</a></li>
        </ul>
        <ul class="nav nav-sidebar">
          <li class="active"><a href="#">Projects <span class="sr-only">(current)</span></a></li>
          <li><a href="agile1.html">Agile 1</a></li>
          <li><a href="#">Agile 2</a></li>
          <li><a href="#">Agile 3</a></li>
        </ul>
      </div>
    </div>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
  <script src="js/bootstrap.min.js"></script>
  <script src="js/holder.min.js"></script>
</body>

这是一个示例页面,其中不会加载任何CDN /引用:

<!doctype html>
<html>
{{> header}}
<script type="text/javascript" src="/js/project.js"></script> 
<div class="row placeholders">
    <div class="container">
        <h1>Project Details</h1>
        <br>
    </div>
</div>
</html>

我的控制台中的“网络”标签返回404 /在所有CDN和引用中找不到。我的网页大约有一半有此问题。另一半很好。

这是一个有效网页的例子 - 所有CDN&amp;引用加载:

<!doctype html>
<html>
{{> header}}
<script type="text/javascript" src="/js/home.js"></script> 
    <div class="row placeholders">
 <h2 class="sub-header">Search for a Project</h2>
          <div class="table-responsive">
            <h1>Hi</
    <div>
</html>

以下是我如何从服务器向客户端发送数据:

hbs.registerPartials(__dirname + '/../views/partials');
hbs.registerHelper('json', function(context) {
  return JSON.stringify(context);
});

module.exports = function (req, res) {
    var context = {};
    request('http://localhost:3000/api/single_project/' + req.params.id, function (err, resp1, body) {
        context.project = JSON.parse(body);
        request('http://localhost:3001/api/reports/' + req.params.id, function (err, resp2, body2) {
            context.report = JSON.parse(body2);
            //console.log(context.report[0]);
            context.report.forEach(function(report) {
                report.startdate = dateFormat(report.startdate, "yyyy-mm-dd");
                report.enddate = dateFormat(report.startdate, "yyyy-mm-dd");
            });
            res.render('../views/project', context);
        });
    });
};

有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

是否在您尝试将标头加载到的每个页面上加载了jQuery? (假设您正在使用$.ajax来获取把手的部分内容。)