【问题标题】:CSS and JS are working on localhost, but not on Heroku WebserverCSS 和 JS 在 localhost 上工作,但不在 Heroku Webserver 上
【发布时间】:2019-09-21 00:06:47
【问题描述】:

伙计们,我一直在开发 Web 平台,但在部署到 heroku 服务器时遇到了一些问题。我的 CSS 和 JS 文件无法加载,尽管这些文件已上传到 heroku。

我正在使用 PHP7 和 Bootstrap 4.0。我已经验证了 CSS 和 JS 链接的路径。我实际上使用 php 包含将我的 head.php 链接到我的主文件 (index.php)。这是代码:

<!-- Bootstrap CSS First Try with the "relative" path used on heroku-->
<link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css">
<!-- General CSS -->
<link rel="stylesheet" href="assets/css/main_style.css">
<!-- Fav Icon -->
<link rel="icon" type="image/png" sizes="32x32" href="assets/imgs/favicon-32x32.png">

<!-- Bootstrap CSS Second Try with the "absolute" path used on heroku-->`enter code here`
<link rel="stylesheet" href="https://whispering-waters.herokuapp.com/vendor/twbs/bootstrap/dist/css/bootstrap.min.css">
<!-- General CSS -->
<link rel="stylesheet" href="https://whispering-waters.herokuapp.com/assets/css/main_style.css">
<!-- Fav Icon -->
<link rel="icon" type="image/png" sizes="32x32" href="https://whispering-waters.herokuapp.com/assets/imgs/favicon-32x32.png">


<!-- Bootstrap CSS Third Try with CDN-->
<link rel="stylesheet" href="<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- General CSS -->
<link rel="stylesheet" href="https://whispering-waters-50467.herokuapp.com/assets/css/main_style.css">
<!-- Fav Icon -->
<link rel="icon" type="image/png" sizes="32x32" href="https://whispering-waters-50467.herokuapp.com/assets/imgs/favicon-32x32.png">

我原以为这会修复 Heroku 上的 CSS 和 JS 加载问题。我接受任何建议。提前致谢

【问题讨论】:

  • 应用程序/页面是否已上线以进行检查?
  • 好吧,你在某一时刻有href="&lt;link rel="stylesheet" href="https://...;这是不对的。此外,文本enter code here 导致其余链接位于正文中;你可能想调查一下。
  • 那么你在查看页面源码的时候看到了吗?您在控制台的网络面板中看到了什么?
  • 像https://whispering-waters.herokuapp.com/vendor/twbs/bootstrap/dist/css/bootstrap.min.css 这样的东西不存在;你在那里得到一个 404。
  • 您好,感谢您的回复。首先,我检查了页面是否处于活动状态,这似乎不是问题。 @Mr Lister,对不起,因为这是我在这里的第一个问题,我可能以错误的方式粘贴了它,对此感到抱歉。我会尽快发布正确的代码。

标签: javascript php css heroku composer-php


【解决方案1】:

我想通了。问题是作曲家包管理。我修复了项目作曲家依赖项,它开始工作。 我意识到 NodeJs npm 和其他包管理器也会出现这个问题。如果有人面临同样的问题,值得尝试验证您的包依赖关系。

衷心感谢您的支持。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多