Search code examples
javascriptamazon-web-servicesvue.jshttpsmime-types

Cloudfront serving javascript files as Mime type of Text/plain


A Vue app being statically hosted on S3 is serving JS files properly through HTTP, but when the site is accessed through the linked CloudFront URL the app does not load because javascript is received from the server as text type. Are there any setting I can change to remedy this? Thank you so much if you can help. index.html source in dist folder:

    <link rel="stylesheet" href="/font/inter.css" />
  <script type="module" crossorigin src="/assets/index.74e9a26f.js"></script>
  <link rel="modulepreload" href="/assets/vendor.cb99a641.js">
  <link rel="stylesheet" href="/assets/index.7303d77a.css">
</head>
  <body>
    <div id="app"></div>

HTTP site directly to S3

Same settings but on cloudfront HTTPS link


Solution

  • jellycsc solved my problem. I just had to manually change the system-defined content-type in the S3 console for the individual js objects from text/plain to application/javascript, then make sure the cache was invalidated and refreshed on my browser.