You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

部署在亚马逊服务器的网站出现“Refused to execute script...”MIME类型错误

Troubleshooting the Intermittent MIME Type Error for JS Files on AWS

Hey there, let's tackle this frustrating intermittent MIME type issue you're dealing with. First off, a key point to clarify: the type attribute in your HTML won't fix this problem on its own—Chrome (and most modern browsers) prioritize the Content-Type response header sent by your server over the HTML attribute, especially after recent security updates that tightened MIME type validation. Here's a step-by-step breakdown to resolve this:

  • Verify the actual response header from your server
    Open Chrome DevTools, go to the Network tab, refresh the page, and locate the JS files throwing the binary/octet-stream error. Check the Response Headers section: if Content-Type isn't set to application/javascript (the standard MIME type for JS files—note that application/script isn't officially recognized), that's the root cause.

  • Fix AWS resource configuration

    • If you're using S3 to host static assets: When you uploaded the JS files, S3 might have defaulted their Content-Type metadata to binary/octet-stream. You can bulk update these files in the S3 console—select the JS files, go to "Actions" > "Edit metadata", and set Content-Type to application/javascript.
    • If you're using EC2 with a web server (Nginx/Apache): Check your server's mime types configuration. For Nginx, ensure mime.types includes application/javascript js;; for Apache, confirm AddType application/javascript .js is present in your config.
  • Clear cached content (browser + CDN)
    The intermittent nature of the issue strongly points to caching. Try:

    • Force-refreshing your browser with Ctrl+Shift+R (Windows/Linux) or Cmd+Shift+R (Mac) to bypass local cache.
    • If you're using CloudFront or another CDN, invalidate the cached JS files to ensure visitors get the updated response headers.
  • Check dynamic JS generation (if applicable)
    If your JS files are generated dynamically (e.g., via Node.js, PHP), make sure your backend code explicitly sets the correct Content-Type header before sending the response. For example, in Node.js:

    res.setHeader('Content-Type', 'application/javascript');
    

Recent Chrome security updates have made browsers far stricter about enforcing correct MIME types for executable scripts like JS—so even if this worked before, the tighter validation is now catching the incorrect response headers your server was sending.

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

火山引擎 最新活动