You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IE-11中script标签请求Node API重定向后挂起问题咨询

Fixing IE11 Script Load Hang on 302 Redirect from Node API

I’ve run into this exact IE11 compatibility quirk before—Chrome handles <script> tag 302 redirects seamlessly, but IE11 just chokes and hangs instead of following through to load the actual script. Let’s break down the likely causes and fixes:

1. Cross-Domain & CORS Headers Are Probably the Culprit

IE11 has far stricter rules for cross-domain script loading than modern browsers, especially when 302s jump to another server:

  • Double-check that the server hosting actual-script.js sends proper CORS headers, specifically Access-Control-Allow-Origin set to your web app’s domain (or * if your use case allows open access).
  • IE11’s old XDomainRequest mechanism also blocks custom headers in cross-domain responses. If your Node API includes any custom headers in the 302 response, strip them out—they might be throwing IE11 off.

2. Skip the 302 Entirely (The Most Reliable Fix)

IE11’s <script> tag support for 302 redirects is notoriously flaky. Instead of redirecting, modify your Node API to proxy the script content directly:

  • Have your API fetch actual-script.js from the target server, then send the raw script content back to the frontend with the correct Content-Type: application/javascript header.
  • Here’s a quick Express example:
app.get('/your-script-endpoint', async (req, res) => {
  try {
    const scriptRes = await fetch('https://other-server.com/actual-script.js');
    const scriptContent = await scriptRes.text();
    res.set('Content-Type', 'application/javascript');
    res.send(scriptContent);
  } catch (err) {
    res.status(500).send('Failed to load script resource');
  }
});

3. Manually Handle Redirects with XHR for IE11

If you can’t change the API’s redirect behavior, add a browser-specific workaround:

  • Detect IE11, then use XMLHttpRequest to fetch the script, manually follow the 302 redirect, and inject the script content into the page dynamically:
function loadAppScript(scriptUrl) {
  // Check for IE11
  if (window.navigator.userAgent.includes('Trident/7.0')) {
    const xhr = new XMLHttpRequest();
    xhr.open('GET', scriptUrl, true);
    
    xhr.onreadystatechange = () => {
      if (xhr.readyState === 4) {
        if (xhr.status === 200) {
          // Inject the script content directly
          const scriptTag = document.createElement('script');
          scriptTag.textContent = xhr.responseText;
          document.body.appendChild(scriptTag);
        } else if (xhr.status === 302) {
          // Follow the redirect manually
          loadAppScript(xhr.getResponseHeader('Location'));
        }
      }
    };
    
    xhr.send();
  } else {
    // Use standard script tag for modern browsers
    const scriptTag = document.createElement('script');
    scriptTag.src = scriptUrl;
    document.body.appendChild(scriptTag);
  }
}

// Initialize the script load
loadAppScript('/your-node-api-script-path');

4. Verify IE11 Security Settings

Occasionally, IE11’s default security policies block cross-domain redirects:

  • Open IE11’s Internet Options > Security > Custom Level, then make sure "Access data sources across domains" is set to Enable or Prompt.
  • For local development, add both your web app domain and the target script server to IE11’s Trusted Sites list.

内容的提问来源于stack exchange,提问作者Joel Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:14:23