html - 使用 Font Awesome Kit 时,CORS 策略已阻止访问脚本
问题描述
我一直在关注 Font Awesome 指南如何使用他们的工具包,但是当我在body
标签末尾插入此代码时,出现错误,并且我无法使用任何图标。
<script src="https://kit.fontawesome.com/a4c00a89bc.js" crossorigin="anonymous"></script>
这是完整的 HTML 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" href="imgs/favicon.ico" />
<link rel="apple-touch-icon" href="imgs/logo192.png" />
<link rel="stylesheet" type="text/css" href="scss/main.css">
<title>My title</title>
</head>
<body>
<div>Facebook<i class="fab fa-facebook"></i></div>
<script src="https://kit.fontawesome.com/a4c00a89bc.js" crossorigin="anonymous"></script>
</body>
</html>
这是错误消息:
Access to script at 'https://kit.fontawesome.com/a4c00a89bc.js' from origin 'http://localhost:63342' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
GET https://kit.fontawesome.com/a4c00a89bc.js net::ERR_FAILED
任何想法?
解决方案
看起来 JavaScript 调试服务器导致了这个问题,我使用的是 Live Edit 插件。当我重新启动服务器时,脚本工作了。另外,如果我只是打开 html 文件,它可以正常工作。但是问题总是发生在 JavaScript 调试服务器第一次启动时,当它打开浏览器时。
快速说明:将脚本放在 head 标记之间,因为它将样式表插入到 html 文件中。
(我在 phpStorm 中使用 JavaScript 调试服务器)
推荐阅读
- php - 爱讯 | 阿贾克斯 | 获取异步等待 JS | XMLHttpRequest | 哪些是最好的 PHP 工作?
- reactjs - 使用 ReactJS 导入 Socket 客户端时出现 TypeError
- discord - Discord.js:导出禁令列表命令不起作用
- json - 我可以从我的测试 JSON 服务器使用 GET,但不能使用 PUT 或 POST
- laravel - 如何修复 Laravel 8 Sanctum 的“401 Unauthorized”错误?
- c - 如何从 Linux Kernel Module (Linux Kernel 5.11.0) 读取文本文件
- java - 如何使用 Spark 从 AWS S3 解压 gz
- cube.js - cube.js 游乐场未正确绘制数据
- java - How do I add two string elements in vector?
- .htaccess - 如何删除影响我的 SEO 的重复网址