SpringMVC caches static resources

Configure in dispatcher-servlet.xml:

Xml code   Favorite code
  1. <!-- Process static resources -->  
  2.     <!-- Uploaded images are cached for one month, other js, css, img resources are cached for one year -->  
  3.     <mvc:resources mapping="/res/**" location="/res/" cache-period="2592000"/>   
  4.     <mvc:resources mapping="/resources/**" location="/resources/" cache-period="31536000"/>   
  5.     <mvc:resources mapping="/css/**" location="/css/" cache-period="31536000"/>  
  6.     <mvc:resources mapping="/js/**" location="/js/" cache-period="31536000"/>  
  7.     <mvc:resources mapping="/img/**" location="/img/" cache-period="31536000"/>  
  8.     <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.
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326341184&siteId=291194637