After clearing the browser cache, the page style cannot be loaded
Here we need to pay attention to a springboot version issue:
The difference between Spring Boot 1.x and 2.x version interceptors for static resource access!
- Spring Boot 1.x version has already done the static resource mapping, so the interceptor will not intercept static resources such as .css and .js
- In Spring Boot 2.x version, static resources will be intercepted by interceptors, and static resources need to be excluded.
1. Question one
The problem is as follows : at the first visit, the style is not accessible (but no error is reported in the request), but after the login is successful, the style access is successful, and the style is gone after clearing the cache.
We suspected that the style was intercepted, so we tried to directly request static resources: we
found that the static resources were indeed intercepted. The logic after interception is as shown in the figure below, that is, there is no session in the webpage before logging in, and the static resources are not requested at this time. of. When the login is successful, there is a session in the web page, and then access to the static resources can pass the interceptor.
By configuring the log in the interceptor, it is found that the static resources are indeed intercepted.
Solution : In the interceptor, exclude the static resource path, and the problem is solved.
After excluding static resources, they will not be blocked:
2. Question two
The requested resource was intercepted, but bootstrap.min.css is still accessible when checked by F12, but the Content-Type type is incorrect. The type should be text/css, but its type is text/html.
The main reason is due to: Resource interpreted as Stylesheet but transferred with MIME type text/html, that is, the result of the original CSS file is treated as a text/html
page for analysis.
Since springboot2.xx intercepts static resources, why does it return a response? Looking forward to your answers! ! !
Regarding this question: the response pages returned have become html
The spring 5.x version that spring boot 2.x depends on is different from the spring 4.3.x version that spring boot 1.5.x depends on. The interceptor for resources is initialized differently. The specific source code is in WebMvcConfigurationSupport.
Reference blog: https://blog.csdn.net/ln1593570p/article/details/80607616