Sunday, February 18, 2024

MIME type text html

 


What

Last week, we faced MIME type error after the hosted server upgrade.  

Loading module from “runtime.4c09d92ae7f4a186.js” was blocked because of a disallowed MIME type (“text/plain”).  Strict MIME type checking is enforced for module scripts per HTML spec.

By design, Angular web app is hosted using AWS S3 and CloudFront architecture.

Where

These issues were related to three build files namely main.js, runtime.js and polyfills.js 

Why

Due to recent server upgrade process, Angular build files were uploaded into AWS to render as text/html by default. 

How

Fix is to upload files to s3 and specify the content-type in metadata for js files explicitly as below:

aws s3 sync $DIST_PATH/ s3://$BUCKET_NAME/ --include "*.js" --content-type "application/javascript"


No comments:

Post a Comment