I have exactly the same problem as author of this question: Preventing iframe caching in browser - url within my iframe is cached. I request sort of an overkill anti-caching policy in my headers and Fiddler shows the youtube video (the page within the iframe) is not cached either, just the URL is the same every time I reload the page with the iframe.
What is different? The few answers for the linked question that might work suppose the iframe is built dynamically by JavaScript. But I made my iframe as a plain, static HTML, just with few parameters inserted dynamically by php. Making just this one feature of whole website (it is not big) through JavaScript would be possible as a workaround, but I would rather stick with php/html.
So: is it possible to prevent caching of URL within an iframe without JavaScript? If yes, how?
EDIT - my code:
$videoUrl = 'xL0NjTDgwY4';
$x = rand();
echo '<iframe id="player2" type="text/html" ';
echo 'src="http://www.youtube.com/embed/'.$videoUrl.'?enablejsapi=1&origin=http://e-history.cz&n="'.$x;
echo '></iframe>';
Fiddler shows:
Host: www.youtube.com
URL: /embed/M7lc1UVf-VE?enablejsapi=1&origin=http://example.com
Caching: no-cache; Expires: Tue, 27 Apr 1971 19:44:06 EST
Caching for the outer page on my web: no-store, no-cache, must-revalidate, post-check=0, pre-check=0; Expires: Thu, 19 Nov 1981 08:52:00 GMT
Ask for other fields if needed.
The URL shown by Fiddler is the URL I had there for the first time, when I copied an iframe template from YouTube Player API (the second code block in the link, where iframe in plain HTML is shown.
My caching related headers (in .htaccess):
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
And in meta:
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
The expiration date shown in Fiddler suggests that I ordered even more anti-caching headers when I though I had a caching problem. It is theoretically possible that these duplicities cause the problem, though it seems unlikely.
One more information that might be relevant: I have another iframe on my website, and it works as it should, no caching except for what is usual for Google Maps. Code for this working iframe:
if(isset($kml)) {
$adr = 'https://maps.google.com?q='.$kml.'&ll=';
} else {
$adr = 'https://maps.google.com?ll=';
}
$adr .= $lat.','.$lon.'&z='.$zoom;
$adr .= '&t=h&output=embed';
echo '<iframe class="mapa" src="'.$adr.'"></iframe>';