spring-framework: Regression: Static JS files served as 'application/octet-stream' instead of 'application/javascript' [SPR-14368]

Luis Lebolo opened SPR-14368 and commented

I 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 config looks like

<!-- ... -->
<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 (maybe #17493).

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. Unfortunately, I don’t think I could package up the project - it’s quite complex and lots of proprietary info.


Affects: 4.3 GA

Reference URL: http://stackoverflow.com/questions/37822460/upgraded-to-spring-4-3-0-and-static-js-files-are-now-served-as-application-octe

Issue Links:

  • #18233 ResourceHttpRequestHandler does not take into account mime types configured in WebMvcConfigurerAdapter

Referenced from: commits https://github.com/spring-projects/spring-framework/commit/e38623df87cf6cbc529724d6cf1170874c05bcf0

0 votes, 5 watchers

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 24 (3 by maintainers)

Most upvoted comments

@simararneja Could you create a minimal sample application (using start.spring.io) that replicates the problem? Then could you create a new issue for that? Thanks!