hoythan
V2EX  ›  问与答

如何优化跨域请求时 OPTIONS 的请求速度(NGINX)

  •  
  •   hoythan · Apr 13, 2018 · 2396 views
    This topic created in 3046 days ago, the information mentioned may be changed or developed.

    因为接口涉及到跨域问题,每次接口请求时都有接近 600 毫秒是 OPTIONS 请求浪费的时间,如何优化这一过程,例如 nginx 配置跨域直接返回而不经过程序处理( php )

    oott123
        1
    oott123  
       Apr 14, 2018 via Android   ❤️ 1
    从前端角度,可以(用一些反模式)把请求尽量优化成简单请求或者缓存 preflight 结果,避免频繁 preflight

    nginx 的话你写个 if 判断 method,然后设置对应的 cors 头,并且 return 200 就行了,好像没啥很复杂的?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   933 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 77ms · UTC 19:53 · PVG 03:53 · LAX 12:53 · JFK 15:53
    ♥ Do have faith in what you're doing.