浏览器何时不向服务器请求文件?
换句话说,我有一个JavaScript文件正在服务.其HTTP响应报头具有一个ETag,Cache-Control: public和Expires: Tue, 19 Jan 2038 03:14:07 GMT.
304浏览器缓存已准备好后服务器返回a .
我的问题是,为什么浏览器甚至检查服务器并首先获得一个304?我不希望浏览器询问是否有新版本 - 它应该直接从浏览器缓存加载而不检查服务脚本的服务器的修改.
HTTP响应头的哪些组合实现了这一点?
在我正在调试的Web应用程序中,索引页面如下所示.
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="renderer" content="webkit" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link rel='stylesheet' href='u.css?1456217719620'></link>
<link rel='stylesheet' href='ll.css?1456217719620'></link>
<link rel='stylesheet' href='aa.css?1456217719620'></link>
<script src='c.js?NaN'></script>
<link rel="shortcut icon" href="/images/favicon.ico" />
<script src='ll1.js?1456217719620'></script>
<script src='ll2.js?1456217719620'></script>
<script src='ll3.js?1456217719620'></script>
<script src='ll4.js?1456217719620'></script>
<script src='ll5.js?1456217719620'></script>
<script src='ll6.js?1456217719620'></script>
<script src='aa.js?1456217719620'></script>
</head>
<body>
<!-- Edit: As suggested in one of the reply, could it be because there are scripts like this in body? -->
<script …Run Code Online (Sandbox Code Playgroud) 看下面的代码。Chrome 在调试控制台中记录了一个请求。如果这是因为缓存,为什么它不记录两个请求,最后一个是 304?
什么解释了这种浏览器行为?
<script>
new Image().src="//stackoverflow.com/"
new Image().src="//stackoverflow.com/"
</script>
Run Code Online (Sandbox Code Playgroud)