【问题标题】:Page served locally cannot find assets in parent folders of root本地服务的页面在根目录的父文件夹中找不到资产
【发布时间】:2014-08-07 11:22:07
【问题描述】:

我正在使用本地网络服务器来提供一个简单的静态 html 页面。该项目具有以下文件夹结构:

/site
  /build
    index.html
  /bower_components

Index.html 可通过http://localhost:5455/ 访问。在 index.html 中,我正在从 ../bower_components 加载一些资产:

<link rel="stylesheet" href="../bower_components/normalize.css/normalize.css">
<script src="../bower_components/jquery/dist/jquery.min.js"></script>

但 firefox 或 chrome 似乎都无法从该父文件夹加载资源。我收到以下错误:

无法获取 /bower_components/jquery/dist/jquery.min.js

所以看起来它不是在寻找父 ../bower_components,而是在 build/bower_components,这显然是不正确的。为什么会这样,它是某种安全协议吗?我该如何纠正这个问题?

【问题讨论】:

    标签: javascript html css localhost


    【解决方案1】:

    如果您的服务器映射到build 文件夹,出于明显的安全原因,您将永远无法访问父文件夹! 一些解决方案是:

    1 - 将您的服务器根映射到 site 文件夹

    2 - 将 bower_components 文件夹放入 build 文件夹

    【讨论】:

    • 好的,有道理。解决方案 1 对我有用。不幸的是,开发站点的根目录(现在是 localhost/build)不能与 dist 版本的根目录相同(dist 构建任务会将所有脚本移动到根目录中),但至少它现在可以工作。谢谢!
    【解决方案2】:

    您确实将 /build 文件夹绑定到 Web 服务器的根目录。 在尝试在 HTML 中引用它之前,您必须将 /bower_components 绑定到某种网络服务地址。

    【讨论】:

      猜你喜欢
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多