zoukankan      html  css  js  c++  java
  • Script error.解决方法

    1. 添加 crossorigin="anonymous" 到script标签

    <script src="https://xxx.com/xxx.js" crossorigin="anonymous"></script>

    crossorigin可以取枚举值anonymous或则use-credentials

    The “anonymous” keyword means that there will be no exchange of user credentials via cookies, client-side SSL certificates or HTTP authentication

    anonymous即不发送Cookie和HTTP认证信息,对于静态资源,我们使用anonymous就已经足够。 关于crossorigin详情可以参考: CORS settings attributes

    2. 添加支持跨域访问的设置

    Access-Control-Allow-Origin: *

    Access-Control-Allow-Origin是HTML5中定义的一种解决资源跨域的策略。他是通过服务器端返回带有Access-Control-Allow-Origin标识的Response header,用来解决资源的跨域权限问题。

    CDN服务商比如七牛默认已经配置好了Access-Control-Allow-Origin,使用curl命令获取头部:

    curl --head https://js.fundebug.cn/fundebug.0.0.4.min.js | grep "Access-Control-Allow-Origin"

    结果如下:


    如果您有单独的子域名(子域名也会被认定为不同源)用来分发静态资源,那么需要在服务端做一点配置。针对不同语言和框架的配置方法我们不一一列出,Nodejs的Express框架下是这样配置的:

    app.use(function(req, res, next)
    {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
    next();
    });

    其它设置Access-Control-Allow-Origin请参考

    https://blog.fundebug.com/2017/04/05/understand-script-error/
    https://blog.fundebug.com/2017/04/06/test-script-error/
    https://blog.fundebug.com/2017/04/07/solve-script-error/

  • 相关阅读:
    linux安装jdk1.8
    Python中import
    Python时间
    Python学习Json
    Hive命令学习
    Hadoop系统中的一些概念
    Hadoop系统命令
    ssh无密码登录设置
    Python学习
    Linux Socket IPC
  • 原文地址:https://www.cnblogs.com/zhishaofei/p/9709112.html
Copyright © 2011-2022 走看看