首页 > 解决方案 > CSS 和 JS 在 localhost 上工作,但不在 Heroku Webserver 上

问题描述

伙计们,我一直在 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 加载问题。我接受任何建议。提前致谢

标签: javascriptphpcssherokucomposer-php

解决方案


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

我衷心感谢您的支持。


推荐阅读