C
C
Carlyndow Marlifi2021-06-08 16:41:13
PHP
Carlyndow Marlifi, 2021-06-08 16:41:13

What is the best way to reset the cache of site users?

Suppose all users have a cached site (js / css / img)
You have cooked a delicious borscht, to eat which you need to clear the cache.

I do like this:

#code (PHP)

$cache_url = '?08062021'; 
echo '<img src="img.png'.$cache_url.'">';


If you need to update the cache, just change the value of the variable.
There are other options? Are there better options? Is this acceptable at all?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Spartak (Web-StyleStudio), 2021-06-08
@Spartak-2205

Alternatively, you can use the filemtime function

echo '<img src="img.png?'.filemtime('img.png').'">';

L
Lev Zabudkin, 2021-06-08
@zabudkin

$cache_url = '?' . time(); 
echo '<img src="img.png' . $cache_url.'">';

In general, in order not to be cached, then at the beginning of the script:
<?php
ob_clean();
ob_start();
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question