配置
spring.mvc.static-path-pattern=/static/** spring.resources.cache.cachecontrol.max-age=30s spring.resources.cache.cachecontrol.s-max-age=50s
啟動項目
http://127.0.0.1:8080/static/spring.png
再次請求
添加header
If-Modified-Since
降配置改為
spring.mvc.static-path-pattern=/static/** spring.resources.cache.cachecontrol.no-cache=true
說明:
Last-Modified 是由服務器往客戶端發送的 HTTP 頭
If-Modified-Since是由客戶端往服務器發送的頭
在瀏覽器第一次請求某一個URL時,服務器端的返回狀態會是200,內容為訪問的資源
客戶端再請求該URL時,瀏覽器會向服務器傳送 If-Modified-Since 頭,如果資源沒有變化,則自動返回 HTTP 304,內容為空