Kyl*_*ndt 10 iis http cache iis-7.5
我有一些带有缓存控制Max-Age标头的静态内容,因此客户端将缓存静态内容。但是,当有错误响应建议客户端缓存它时,IIS 7.5 仍会发送此标头。
具有负面影响,某些代理将缓存该错误响应。我可以,Vary: Accept,Accept-Encoding但这并没有真正解决Max-Age错误响应的根本问题。
当前相关的 IISweb.config部分是:
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
有没有办法让我可以做到这样我们就不会告诉客户端或代理缓存 400/500 错误代码?
我创建了一个基本的测试“套件”。
当我在 IIS 7.0(.NET 4.0 上的集成管道模式)上使用最小的 Web.config 运行测试时,一切都通过了;Cache-Control当测试文件的private请求Accept头与文件的Content-Type.
这让我相信您有一些模块中断了 IIS 的静态缓存例程,或者 IIS 7.0 和 7.5 在这里有所不同。
这是我使用的文件(没有,some-script.js因为它只是一个空文件):
Web.Config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
</system.web>
<system.webServer>
<staticContent>
<!-- Set expire headers to 30 days for static content-->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
test.html:
<!doctype html>
<html>
<head>
<title>http://serverfault.com/questions/346975</title>
<style>
body > div
{
border:1px solid;
padding:10px;
margin:10px;
}
</style>
</head>
<body>
<div>
<h2>Request JS file with Accepts: accept/nothing</h2>
<b>Response Headers: </b>
<pre id="responseHeaders-1">loading&hellip</pre>
</div>
<div>
<h2>Request JS file with Accepts: */*</h2>
<b>Response Headers: </b>
<pre id="responseHeaders-2">loading&hellip</pre>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var responseHeaders1 = $("#responseHeaders-1"),
responseHeaders2 = $("#responseHeaders-2"),
fetchScript = function (accepts, element, successMsg, errorMsg) {
var jXhr = $.ajax({
// fetch the resource "fresh" each time since we are testing the Cache-Control header and not caching itself
"url": "some-script.js?" + (new Date).getTime(),
"headers": {
"Accept" : accepts
},
"complete": function () {
var headers = jXhr.getAllResponseHeaders();
headers = headers.replace(/(Cache-Control:.+)/i, "<strong><u>$1</u></strong>");
element.html(headers);
},
"success": function () {
element.after("<div>" + successMsg + "</div>");
},
"error": function () {
element.after("<div>" + errorMsg + "</div>");
}
});
};
fetchScript("accept/nothing", responseHeaders1, "Uh, your server is sending stuff when the client doesn't accept it.", "Your server (probably) responded correctly.");
fetchScript("*/*", responseHeaders2, "Your server responded correctly.", "Something went wrong.");
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3065 次 |
| 最近记录: |