Configure in dispatcher-servlet.xml:
- <!-- Process static resources -->
- <!-- Uploaded images are cached for one month, other js, css, img resources are cached for one year -->
- <mvc:resources mapping="/res/**" location="/res/" cache-period="2592000"/>
- <mvc:resources mapping="/resources/**" location="/resources/" cache-period="31536000"/>
- <mvc:resources mapping="/css/**" location="/css/" cache-period="31536000"/>
- <mvc:resources mapping="/js/**" location="/js/" cache-period="31536000"/>
- <mvc:resources mapping="/img/**" location="/img/" cache-period="31536000"/>
- <mvc:resources mapping="/images/**" location="/images/" cache-period="31536000"/>
After this configuration, SpringMVC will automatically add the cache header Cache-Control and Expires values to the static resource Response, as shown in the following figure:
The request status is 403, the image will not be obtained from the server again, and the browser cache is used to save the requested traffic and request time.