【问题标题】:CORS errors accessing //polymer-project.org/components访问 //polymer-project.org/components 时出现 CORS 错误
【发布时间】:2014-10-08 06:09:10
【问题描述】:

我正在尝试使用可在 http://polymer-project.org 上托管的 Polymer 组件版本来试验 Polymer,直到出现真正的 CDN(根据常见问题解答)。不幸的是,导入组件总是失败并出现 CORS 错误。

现在我的代码看起来像这样,并不复杂:

<!doctype html>
<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <script src="//polymer-project.org/components/platform/platform.js"></script>
  <link rel="import" href="//polymer-project.org/components/font-roboto/roboto.html"/> 
</head>

<body>
</body>
</html>

但我在加载 roboto.html 时从 Chrome 中收到此错误:

在源“http://polymer-project.org”的重定向已被跨域资源共享策略阻止加载:请求的资源上不存在“Access-Control-Allow-Origin”标头。

这应该可行,对吧? roboto.html 已启用 CORS,并且我已验证它正在发送 Access-Control-Allow-Origin: * 标头,那么为什么这不起作用?

【问题讨论】:

    标签: http cors polymer


    【解决方案1】:

    页面polymer-project.org/components/platform/platform.js 重定向到www.polymer-project.org/components/platform/platform.js。前者不发送Access-Control-Allow-Origin 标头。

    尝试使用www 子域引用资源:

    <script src="//www.polymer-project.org/components/platform/platform.js"></script>
    

    roboto.html 引用应用同样的方法:虽然它不会导致错误,但在每个页面视图上它都是无用的重定向。

    【讨论】:

      猜你喜欢
      • 2017-09-23
      • 2017-04-24
      • 2019-06-28
      • 2021-10-30
      • 2021-09-24
      • 1970-01-01
      • 2020-08-13
      • 2021-11-18
      • 2018-03-19
      相关资源
      最近更新 更多