I'm using Thymeleaf with Spring Boot. When loading a page of the project site, it says that my script is being blocked because it is being returned as json instead of text/javascript.
I've included the script in the html using standard Thymeleaf templating like this:
<script type="text/javascript" th:src="@{/js/admin-register-users.js}" defer></script>
I've set up resource handling in the following way:
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/img/");
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
WebMvcConfigurer.super.addResourceHandlers(registry);
}
}
For some reason in the browser I get the error:
The resource from “https://localhost:8090/js/admin-register-users.js” was blocked due to MIME type (“application/json”) mismatch (X-Content-Type-Options: nosniff).
Turned out to be that the file was not being found, and so a json response was returned from the server, but that response was being blocked and could not be read.
Long story short, was nothing to do with resource configuration. File was not being generated from TypeScript. So the server only found an empty js folder.