Saya membuat "suite" uji dasar.
Ketika saya menjalankan tes dengan Web.config minimal pada IIS 7.0 (mode pipeline terintegrasi pada. NET 4.0) semuanya berlalu; Cache-Control
header respons file tes diatur ke private
saat Accept
header permintaan tidak cocok dengan file Content-Type
.
Ini membuat saya percaya bahwa Anda memiliki beberapa modul yang mengganggu rutin caching statis IIS atau IIS 7.0 dan 7.5 berbeda di sini.
Berikut adalah file yang saya gunakan (tanpa some-script.js
file yang kosong):
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>
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>