1

i know this question has been asked many times but i still cant get this to work. I think it would help for someone to come up with a solution based around my situation.

i have a random-video.php page that generates a random video from an array, this works fine and doesn't cache in chrome:

<?php
$array = [
    "http://www.mentor-distribution.com/media/Introducing_MConnect.mp4",
    "http://www.mentor-distribution.com/media/hs_freedom_chair.mp4",
 "http://www.mentor-distribution.com/media/quickstand.mp4",
 "http://www.mentor-distribution.com/media/MFlex.mp4"
];
$randomIndex = array_rand($array);
$random = $array[$randomIndex];
?>

<iframe width="320" height="187" frameborder="0" allowfullscreen src="<?php echo htmlspecialchars($random); ?>"></iframe>

This is the section html page trying to display the random video each time, but once loaded it doesn't change video until you clear cache:

<div class="rightsidevid"><iframe width="320" height="187" src="http://mentor-distribution.com/internal/random-video.php" frameborder="0" scrolling="no" allowfullscreen></iframe></div>

If anyone can help it would be greatly appreciated. I'm sure you can achieve this by having a number at the end of the url (e.g. url?RandomGenNumber), but I am not sure how to do this.

Carl Piper
  • 81
  • 2
  • 9

3 Answers3

0

Not sure if this would work for Chrome; however, Firefox has the same problem. I have tried the following work around on Firefox and it did work:

<iframe src="webpage.html?var=xxx" id="article"></iframe>
<script>
var article = document.getElementById("article");
article.contentWindow.location.href = article.src;
</script>
0

I got it to work in Chrome by setting the following cache settings to my .htaccess file.

##
# Expires Headers YSlow START
# Browser caching optimization by Sam Riveros
##

<IfModule mod_headers.c>

 # Turn on Expires and set default to 0
 ExpiresActive On
 ExpiresDefault A0
 
 # Set up caching on media files for 1 year (forever?)
 <FilesMatch "\.(ico|pdf|mp4|ogg|webm|svg+xml|ttf|otf|woff|woff2)$">
  ExpiresDefault A29030400
  Header append Cache-Control "public"
 </FilesMatch>

 # Set up caching on media files for 1 week
 <FilesMatch "\.(jpg|jpeg|png)$">
  ExpiresDefault A604800
  Header append Cache-Control "public"
 </FilesMatch>
 
 # Set up caching for commonly updated static files for 1 week
 <FilesMatch "\.(txt|html|js|css)$">
  ExpiresDefault A604800
  Header append Cache-Control "proxy-revalidate"
 </FilesMatch>
 
 # Force no caching for dynamic files
 <FilesMatch "\.(php)$">
  ExpiresActive Off
  Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
  Header set Pragma "no-cache"
 </FilesMatch>

</IfModule>

<IfModule mod_expires.c>

 #Redundancy in case server admin turn mod_headers.c off

 ExpiresActive on
 ExpiresDefault          "access plus 1 month"
 
 #CSS
 ExpiresByType text/css        "access plus 1 year"

 #Data interchange
 ExpiresByType application/json      "access plus 0 seconds"
 ExpiresByType application/xml      "access plus 0 seconds"
 ExpiresByType text/xml        "access plus 0 seconds"
 
 #Favicon
 ExpiresByType image/x-icon       "access plus 1 year"
 
 #HTML components (HTCs)
 ExpiresByType text/x-component      "access plus 1 month"
 
 #HTML
 ExpiresByType text/html        "access plus 1 week"
 
 #Javascript
 ExpiresByType application/javascript    "access plus 1 year"
 
 #Manifest files
 ExpiresByType application/x-web-app-xanifest+json "access plus 0 seconds"
 ExpiresByType text/oache-xanifest     "access plus 0 seconds"
 
 #Media
 ExpiresByType image/jpg        "access plus 1 week"
 ExpiresByType image/jpeg       "access plus 1 week"
 ExpiresByType image/png        "access plus 1 week"
 ExpiresByType audio/ogg        "access plus 1 year"
 ExpiresByType video/mp4        "access plus 1 year"
 ExpiresByType video/ogg        "access plus 1 year"
 ExpiresByType video/webm       "access plus 1 year"

 #Web feeds
 ExpiresByType application/atom+xml     "access plus 1 hour"
 ExpiresByType application/rss+xml     "access plus 1 hour"
 
 #Web fonts
 ExpiresByType image/svg+xml       "access plus 1 year"
 ExpiresByType application/x-font-ttf    "access plus 1 year"
 ExpiresByType application/x-font-truetype   "access plus 1 year"
 ExpiresByType application/x-font-opentype   "access plus 1 year"
 ExpiresByType application/font-woff     "access plus 1 year"
 ExpiresByType application/font-woff2    "access plus 1 year"
 ExpiresByType application/vnd.ms-fontobject   "access plus 1 year"
 ExpiresByType application/vnd.xs-fontobject   "access plus 1 year"
 ExpiresByType application/font-sfnt     "access plus 1 year"

</IfModule>

<IfModule mod_deflate.c>

 # Compress HTML, CSS, JavaScript, Text, XML and fonts
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE application/rss+xml
 AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
 AddOutputFilterByType DEFLATE application/x-font
 AddOutputFilterByType DEFLATE application/x-font-opentype
 AddOutputFilterByType DEFLATE application/x-font-otf
 AddOutputFilterByType DEFLATE application/x-font-truetype
 AddOutputFilterByType DEFLATE application/x-font-ttf
 AddOutputFilterByType DEFLATE application/x-javascript
 AddOutputFilterByType DEFLATE application/xhtml+xml
 AddOutputFilterByType DEFLATE application/xml
 AddOutputFilterByType DEFLATE font/opentype
 AddOutputFilterByType DEFLATE font/otf
 AddOutputFilterByType DEFLATE font/ttf
 AddOutputFilterByType DEFLATE image/svg+xml
 AddOutputFilterByType DEFLATE image/x-icon
 AddOutputFilterByType DEFLATE text/css
 AddOutputFilterByType DEFLATE text/html
 AddOutputFilterByType DEFLATE text/javascript
 AddOutputFilterByType DEFLATE text/plain
 AddOutputFilterByType DEFLATE text/xml

 # Remove browser bugs (only needed for really old browsers)
 BrowserMatch ^Mozilla/4 gzip-only-text/html
 BrowserMatch ^Mozilla/4\.0[678] no-gzip
 BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 Header append Vary referer

</IfModule>

##
# Expires Headers YSlow END
##
0

The Expires Headers YSlow START by Sam Riveros is a very good thing to have if you don't already. It will help optimize your website. However, the only line you need to correct the issue is Header append Vary referer. Add the following to your .htaccess file and it should work fine without the need for anything else. Not even JavaScript:

<IfModule mod_deflate.c>

 Header append Vary referer

</IfModule>