7

簡単な HTML コード:

<img src="http://someaddr/image.php">

image.php は、すべての必要なキャッシュなしヘッダーを含む静的イメージへのランダムなリダイレクトを返すスクリプトです。

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Location: http://someaddr/random_image_12345.jpg

問題: この HTML ページに前後に移動するとき、Chrome (最新の win/mac) は address を再検証しませんhttp://someaddr/image.php

私はリダイレクト 302 と 303 を使用してみました (RFC では、ブラウザによって決してキャッシュされてはならないというより強い要件があります)。これは、IE、FireFox、Opera で魅力的に機能します。それらは常に更新されhttp://someaddr/image.phpます。しかし、Chrome はそうではありません。

Chrome で開発者ツールを使用したことさえありますが、ネットワーク ログには (キャッシュされているかどうかにかかわらず) フェッチの試みが表示されていないようhttp://someaddr/image.phpです。ネットワーク ログには、http://someaddr/random_image_12345.jpg(キャッシュされた) への接続が 1 つだけ表示されます。なんでこんなに壊れてるんだ…

クエリ文字列を画像ソースに入れる単純で単純な解決策を知っています:

    <img src="http://someaddr/image.php?refresh={any random number or timestamp}">

しかし、私はそのようなハックが好きではありません/使用できません。他のオプションはありますか?

4

2 に答える 2

5

307 リダイレクトを試す

しかし、キャッシュされたリダイレクトが原因で機能しないリンクにアクセスしようとして立ち往生している場合は...

これはキャッシュをクリアしませんが、リダイレクト キャッシュされたリンクにたどり着こうとして髪を引っ張っている場合、これは 1 つの迅速で可能なルートです。

リンク アドレスをアドレス バーにコピーし、GET 情報をアドレスに追加します。

サイトがhttp://example.comの場合

Put a ?x=y at the end of it 
( example.com?x=y ) - the x and y could be anything you want.

すでに ? がある場合 URLの後にいくつかの情報があります

( example.com?this=that&true=t ) - try to add &x=y to the end of it...

( example.com?this=that&true=t&x=y )
于 2013-09-25T23:58:41.613 に答える
-3

別の質問に投稿されたリンクから:

 The first header Cache-Control: must-revalidate means that browser must send validation request every time even if there is already cache entry exists for this object.
Browser receives the content and stores it in the cache along with the last modified value.
Next time browser will send additional header:
If-Modified-Since: 15 Sep 2008 17:43:00 GMT

This header means that browser has cache entry that was last changed 17:43.
Then server will compare the time with last modified time of actual content and if it was changed server will send the whole updated object along with new Last-Modified value.

If there were no changes since the previous request then there will be short empty-body answer:
HTTP/1.x 304 Not Modified

HTTP の etags と最終更新日を使用して、既にキャッシュされているブラウザー データを送信していないことを確認できます。

$last_modified_time = filemtime($file); 
$etag = md5_file($file); 

header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT"); 
header("Etag: $etag"); 

if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time || 
    trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { 
    header("HTTP/1.1 304 Not Modified"); 
    exit; 
} 
于 2012-11-25T18:03:56.200 に答える