[英]Stop image that is linked to in XHR response from being cached
我正在使用XHR獲得一些HTML。 HTML響應包含一個img元素,並且出於某種原因緩存了該圖像。
服務器將圖像與以下標頭一起提供:
cache-control: no-cache, must-revalidate
content-security-policy: default-src 'self'; ...
content-type: image/png
date: Mon, 08 Oct 2018 03:41:00 GMT
expires: Sat, 26 Jul 1997 05:00:00 GMT
server: nginx (Ubuntu)
status: 200
strict-transport-security: max-age=30879000; includeSubDomains; preload
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
XHR的用法如下:
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
addToPage(xmlHttp.responseText);
}
};
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xmlHttp.send();
XHR響應示例:
<h1>Title</h1>
<p>Stuff</p>
<img src="/captcha-generator">
不使用XHR時,它可以按預期工作。 出於某種原因,當從XHR響應中鏈接圖像時,將對其進行緩存。
為什么要緩存圖像,以及如何強制瀏覽器獲取新圖像?
我當然可以附加一個唯一的參數來破壞緩存,(例如/captcha-generator?r={random-string}
但我想避免這種情況。
在開發模式的情況下,它會發生提示。因此,如果Google crome轉到右上角,請單擊costomize並控制Google crome。然后使用新的inconginto窗口打開以打開開發模式
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.