Condition update based on condition

I have a website in which there are 2 states: unpublished and published.

When in the published state, images are served from my CDN with caching set within a month. After posting changes to the file is not allowed, so I never worry about it.

However, when in an unpublished state, I want the page to refresh every time it is viewed. The user makes an update, browses their contents to see a new file that has been hard updated to view the latest updates.

How can I get a hard update based on whether the page is in a published or unpublished state?

+4
source share
2 answers

Using a similar idea with image caching - Disable cache for some images , you can do this using

(1) By adding a randomly generated query string, i.e. ?version=<?php echo time();?>to url page - fooobar.com/questions/80994 / ...
can also be done using javascript - fooobar.com/questions/80994 / ...

(2) Use HTTP headers (in php)

header("Pragma-directive: no-cache");
header("Cache-directive: no-cache");
header("Cache-control: no-cache");
header("Pragma: no-cache");
header("Expires: 0");

fooobar.com/questions/80994 / ...

(3) Using meta HTTP headers

<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">

fooobar.com/questions/80994 / ...

+2
source

I don’t know if I get what you are looking for, but maybe something like this?

$state = "unpublished";

function updatePage($state)
{
   if($state == "unpublished")
   {
   $page = $_SERVER['PHP_SELF'];
   header("Refresh: $sec; url=$page");
   }
}

Call this function whenever an update is performed.

0
source

All Articles