[英]How to stop image caching on a wordpress webpage
I have an image called webcam.jpg on the server.我在服务器上有一个名为 webcam.jpg 的图像。 This image is replaced by a new image every 2 mins with the same name.
该图像每 2 分钟被一个同名的新图像替换。 I have a WordPress page to display this image.
我有一个 WordPress 页面来显示这张图片。
The issue is this image getting cached in the browser, so it shows the old photo.问题是这张图片被缓存在浏览器中,所以它显示的是旧照片。 If I clear the cache, it starts showing the latest image at that time.
如果我清除缓存,它会在那时开始显示最新图像。
I tried the below methods none of them is working for me.我尝试了以下方法,但没有一个对我有用。
<img class="weather-cam-box alignleft" src="/cameraimages/webcam.jpg?2020" alt="" width="100%" height="764" />
<img class="weather-cam-box alignleft" src="/cameraimages/webcam.jpg?2020" alt="" width="100%" height="764" />
<img class="weather-cam-box alignleft" src="/cameraimages/webcam.jpg?342038402" alt="" width="100%" height="764" />
Also, I tried to target this specific page and not cache the content on that page using the below code it didn't help either.此外,我尝试针对此特定页面,而不是使用以下代码缓存该页面上的内容,但它也无济于事。
<?php if ( is_page(22683) ) {?>
<?php nocache_headers(); ?>
<meta http-equiv="cache-control" content="no-cache" />
<?php } ?>
You can try the following steps.您可以尝试以下步骤。
You aren't adding the query string variable.
您没有添加查询字符串变量。 Add variable and unique random number with the timestamp.
添加带有时间戳的变量和唯一随机数。
<img src="/cameraimages/webcam.jpg?nocache=<?php echo time(); ?>">
Add following meta tag to the head
将以下元标记添加到头部
<meta Http-Equiv="Cache-Control" Content="no-cache">
<meta Http-Equiv="Pragma" Content="no-cache">
<meta Http-Equiv="Expires" Content="0">
<meta Http-Equiv="Pragma-directive: no-cache">
<meta Http-Equiv="Cache-directive: no-cache">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.