简体   繁体   English

单击链接时页面刷新

[英]Page refresh when clicking on link

We're having a page where we're serving images from amazon S3 that are getting cached. 我们正在创建一个页面,其中正在提供来自Amazon S3的正在缓存的图像。 However, they've might been changed on a second page. 但是,它们可能已在第二页上进行了更改。 The issue now is that when I click on a link with the url to the previous pages, the images are not reloaded. 现在的问题是,当我单击带有指向先前页面的URL的链接时,图像不会重新加载。

However, doing a refresh in the browser on the page afterwards correctly loads the new images. 但是,此后在页面上的浏览器中进行刷新将正确加载新图像。 I am curious why is that because the image cache headers are correct (as can be seen from manual refresh) and what do to to handle this properly aka reload the new images when going to the previous page with a simple url link? 我很好奇为什么会这样,因为图像缓存头是正确的(可以从手动刷新中看到),并且使用简单的url链接转到上一页时,如何正确地处理此问题又可以重新加载新图像?

You can add a random dummy variable to your link. 您可以在链接中添加随机虚拟变量。 You don't use the value of the variable but the link is different, thus, the brwoser will reload the page without cache. 您不用变量的值,但是链接是不同的,因此,浏览器将重新加载页面而无需缓存。

For example: 例如:

<a href="www.yourweb.com/photos/page.php?rand=4w385fg959">Link</a>

If you have an access to the .htaccess file you can add this 如果您有权访问.htaccess文件,则可以添加此文件

<filesMatch "\.(jpg|jpeg|png|bmp)$">
 FileETag None
 <ifModule mod_headers.c>
    Header unset ETag
    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"
 </ifModule>
</filesMatch>

to prevent chaching images. 以防止图像混乱。

Try This. 尝试这个。

 function myFunction() { location.reload(); 
 <button onclick="myFunction()">Reload page</button> 

Reference : Here 参考: 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM