Survey JS加载缓慢且返回302状态码问题咨询
关于Survey JS脚本加载302重定向及耗时过长的问题
问题描述
加载survey.jquery.min.js时耗时过长,请求返回302状态码。当前在</body>标签前使用以下代码调用脚本:
<script type="text/javascript" src="https://unpkg.com/survey-jquery/survey.jquery.min.js"></script>
请求HTTP头信息
Request Method: GET Status Code: 302 Remote Address: [2606:4700::6810:7aaf]:443 Referrer Policy: strict-origin-when-cross-origin access-control-allow-origin: * cache-control: public, s-maxage=600, max-age=60 cf-cache-status: EXPIRED cf-ray: 79a7e93c7ac371cf-LHR content-type: text/plain; charset=utf-8 date: Thu, 16 Feb 2023 17:13:18 GMT fly-request-id: 01GSDKE0EQKG6989ZPSPDXG931-lhr location: /survey-jquery@1.9.74/survey.jquery.min.js server: cloudflare strict-transport-security: max-age=31536000; includeSubDomains; preload vary: Accept, Accept-Encoding via: 1.1 fly.io x-content-type-options: nosniff :authority: unpkg.com :method: GET :path: /survey-jquery/survey.jquery.min.js :scheme: https accept: */* accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9 sec-ch-ua: "Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110" sec-ch-ua-mobile: ?0 sec-ch-ua-platform: "Windows" sec-fetch-dest: script sec-fetch-mode: no-cors sec-fetch-site: cross-site user-agent: Mozilla/5.0
分析与解决方案
从HTTP头的location字段能看出,unpkg对未指定版本的包请求会返回302重定向,指向具体版本(此处为1.9.74)。这种重定向会多一次额外请求,再加上cf-cache-status: EXPIRED显示缓存已过期,需要从源站拉取资源,双重因素导致加载耗时过长。
这既不是你的调用方式错误,也不是Survey JS本身的问题,属于CDN的正常机制加上缓存过期的偶发情况。解决方法:
- 直接在脚本URL中指定具体版本号,比如:
跳过重定向步骤,直接请求目标资源。<script type="text/javascript" src="https://unpkg.com/survey-jquery@1.9.74/survey.jquery.min.js"></script> - 如果需要最新版本,也可以锁定主版本号(如
@1.x),减少重定向频率,同时保证版本兼容性。
内容的提问来源于stack exchange,提问作者fmcd97
相关产品推荐
相关产品推荐

