Issue
I recently upgraded from Spring 4.2.6 to 4.3.0 and now I'm receiving the following error in Chrome when my web page tries to load static javascript files.
Refused to execute script from
http://.../someJsFile.js
because its MIME type ('application/octet-stream') is not executable, and strict MIME type checking is enabled.
I double-checked the response header (using Spring 4.3.0) and I indeed see Content-Type:application/octet-stream
. However, when I drop back down to Spring 4.2.6 I see Content-Type:application/javascript
.
The files are included in my page like
<!DOCTYPE html>
<html lang="en">
<!-- ... -->
<body>
<!-- ... -->
<!-- Adding type="text/javascript" does not help -->
<script src="/resources/js/someJsFile.js"></script>
</body>
</html>
and my applicationContext.xml has the following config
<!-- ... -->
<context:component-scan base-package="some.package.spec" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
<!-- ... -->
I tried looking at the Spring 4.3.0 release notes, but nothing immediately stood out.
Any ideas what changes in 4.3.0 are affecting me? How do I tell Spring 4.3.0 to set the correct content type for static javascript files? Let me know if you need more details about configuration, etc.
Solution
This bug was added to milestone 4.3.1 (see bug report) and marked as completely resolved on version 4.3.3.
Js modules (mjs) are still served as application/octet-stream by springframework web. In order for them to be served as application/javascript, it is necessary to map the mime type in servlet descriptor (web.xml):
<mime-mapping>
<extension>mjs</extension>
<mime-type>application/javascript</mime-type>
</mime-mapping>
Answered By - lebolo
Answer Checked By - Gilberto Lyons (JavaFixing Admin)