Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

靠谱的跨域解决方案 #50

Open
kangning1206 opened this issue Nov 24, 2018 · 0 comments
Open

靠谱的跨域解决方案 #50

kangning1206 opened this issue Nov 24, 2018 · 0 comments

Comments

@kangning1206
Copy link
Owner

只讲现阶段可用的方案,类似iframe 等技术本次不讨论。

jsonp

josnp利用了script.src属性动态请求,执行回调函数,是一种借用方法。
特点:

  • 只能get请求;
  • 大数据写入适合;
  • 当下浏览器端常用库不支持,比如axios;

前景: 2017年之前还在使用,企业内部可以使用;

跨域资源共享(CORS)

  • axios 极力推荐的;
  • 需要服务器端代码做白名单控制;
  • 原理是 动态写入头:Access-Control-Allow-Origin信息;
  • 浏览器支持受限,IE11及以上;

前景:未来趋势,现代浏览器在向规范靠谱,谁不按套路出牌,谁就得死;
根据业务场景和用户端,推荐使用,好的浏览器没有人会拒绝吧;

proxy

跨域是浏览器为了防止网络安全,规范中的限制,但服务器端是不受限制的,因此在服务器端设置代理;

特点:

  • 同一台服务器压力会略大,性能受一点影响;
  • 配置和架构需要开发和运维一起给出方案

前景:安全级别高。

强力推荐。

WebSocket协议跨域

场景较少,一般web开发不会涉及;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant