Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
?step=image_edit Caching
The cache prevention for images isn’t working in stock 4.9. I’m doing this in ebl_image_edit 3.0 and its a bit ugly to stop it from caching the image.
$('#fullsize-image .content-image').attr('id', 'mainImg');
// Reload image and append random query string to prevent caching. Its always a new image.
$(function() {
var $img = $('#mainImg');
if ($img.length) {
var newSrc = $img.attr('src').split('?')[0] + '?r=' + Math.random();
$img.attr('src', newSrc);
} else {
alert('<img id="mainImg"> not found');
}
});
and
// Include necessary JavaScript and CSS in the head section
public function ebl_image_edit_assets() {
// stop the god damn image caching
$out = '<meta charset="UTF-8">';
$out .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
$out .= '<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0">';
$out .= '<meta http-equiv="Pragma" content="no-cache">';
$out .= '<meta http-equiv="Expires" content="0">';
// Include necessary JavaScript and CSS assets
$out .= '<script src="' . hu . 'textpattern/plugins/ebl-image-edit/jquery.Jcrop.js?v=' . time() . '"></script>';
$out .= '<link rel="stylesheet" href="' . hu . 'textpattern/plugins/ebl-image-edit/jquery.Jcrop.css?v=' . time() . '" type="text/css" />';
$out .= '<script src="' . hu . 'textpattern/plugins/ebl-image-edit/index.js?v=' . time() . '"></script>';
echo $out;
}
Last edited by TheEric (Yesterday 05:07:40)
Offline
Re: ?step=image_edit Caching
As far as I can see, the timestamp appended to the image url was never designed for caching, it’s just the image creation date. And the page itself does not seem to be cached for me (FF), but it can be browser-depending.
Offline
Re: ?step=image_edit Caching
Maybe the caching problem is caused by Cloudflare or some CDN that caches image files, or the website’s .htaccess file having something like:
ExpiresByType image/png "access plus 1 year"
That directive apparently adds a HTTP header that looks like:
Cache-Control: max-age=31536000
So instead of “plus 1 year” maybe try “plus 1 second”. ;-)
Offline
Pages: 1