http状态304表示请求的是缓存,200表示是从服务器请求的。
3张不同的照片,第一次访问,总共请求了4次,
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= "UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<img alt="" width= "200px" src= "static/image1.jpg">
<img alt="" width= "200px" src= "static/image2.jpg">
<img alt="" width= "200px" src= "static/image3.jpg">
</body>
</html>
![](http://upload-images.jianshu.io/upload_images/5548226-811f356ba08eb38f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
然后我们刷新一下,发现200的变成了304,因为图片已经缓存在了本地。
![](http://upload-images.jianshu.io/upload_images/5548226-9035de95c7bc7b8f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
以下是3张相同的image1照片,明显都是存在了本地缓存中
![](http://upload-images.jianshu.io/upload_images/5548226-07a92bd50f917f82.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
加上时间戳目的是为了解决项目更新代码不同步的问题。同理CSS,JS也应该加入时间戳,下次再修改代码的时候避免因为缓存原因没有同步。
<img alt=
""
width=
"200px"
src=
"static/image1.jpg?
<%=System.currentTimeMillis()%>
"
>
原文链接:
http://www.jianshu.com/p/baf46562861d
关注我的公众号,都是满满的干货!
![](https://images2017.cnblogs.com/blog/1216628/201712/1216628-20171230092721554-2013271538.gif)