spring boot配置静态资源及其缓存

配置

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,内容为空

posted @ 2020-04-03 08:50  慕尘  阅读(2568)  评论(0编辑  收藏  举报