The fact that Grav can generate optimized images at specified sizes is great, but what happens to them once they are generated?
Lets say I want to give a new header image a try, so I load a new header image into pages template under a new name…but it doesn’t work out too great. If I overwrite it with a new image of the same name, it doesn’t regenerate.
Is there a way to empty all generated images on the site and have them regenerated as pages are visited? Or maybe even just the one header image?
You just need to delete the image it has generated. If you use firebug or inspect element feature you can easily track down where it is getting the header image from. It looks something like this: images/4/2/0/c/8/420c82349695366defba3f7f5ef1d584a8a6c509-
If you delete that file it will regenerate a new one based on your new image you have submitted.
The easiest and most reliable solution is to flush the Grav cache with bin/grav clear-cache command. This will clear all the generated images and force them all to be regenerated.
We use the Gregwar image library and it has it’s own caching built-in. It caches based on file name + operations. It is not based on the fact that a file timestamp has changed. This ensures the maximum performance, but you an trip it up by replacing the existing image with the same filename. However, with the new file based cache mechanism that is currently sitting in develop, It seems that any file modification change triggers the cache flush. At least i’ve not had any trouble with changing the name of an image lately, but I certainly did experience this in prior versions. I guess I need to investigate it further Good question though!
Hi Andy,
I have experienced a recurring issue with images when I want to update them (e.g. to upload better compressed versions). I confirm that keeping the same file name doesn’t flush the image cache (although I repeatedly deleted everything in the images directory).
Changing the image name causes errors (images not found under their previous names).
I wish I could go with a simple bin/grav clear-cache but so far I have not found the right directory to perform this. Alternatively maybe I should just manually recompile the css?
Every time you change something that is applied to the image, it should re-cache. For example, say you have:
{{ page.media['myimage.jpg'].quality(85) }}
Just changing one paramater:
{{ page.media['myimage.jpg'].quaility(95) }}
Is enough to regenerate the image. If your not changing the signature, then the best approach is to simply clear the image only:
$ bin/grav clear --images-only
This will clear out only the images/ folder where the images are cached, and not the page etc. Also note that bin/grav clear is a shortcut for bin/grav clear-cache.
You must run this at the root of your grav install. So the directory that contains CHANGELOG.md, LICENSE, README.md, composer.json, index.php, etc
Thanks a lot Andy, I am checking with my hosting provider to navigate to the root directory. That will clearly help me better administrate my grav instances)
Now I have changed the images several times during the past month and they did re-cache for a while but I guess the original one came back after a while (hours? days?). I checked this by testing my website on Google Pagespeed Insights (https://developers.google.com/speed/pagespeed/insights/) which is supposed not to cache the pages for more than 30sec. Either I’m missing something or there’s a bug somewhere.
In case this points out something of an issue: I have repeatedly and manually cleared images from the cache without the newer version being taken into account.
I published blog posts (antimatter theme) with post illustrations that needed more compression
I then updated the post images (after further compression via tinypng.com)
Manual tweaks include: deleting content of the /images directory several times, using the Cachebuster plugin (and thus clearing a dozen times) and setting cache expire in the .htaccess file:
I actually think you are getting the updated images. Grav doesn’t have some magical place it puts these files, they are simply manipulated and stored in the images/ folder. If you remove these manually or clear the cache, you will see them being regenerated the next time you request a page with them on.
However, this image library we are using (Imagewar), is probably taking your hightly optimized image (68kb) and then performing its manipulations using PHP’s GD library, creating a new file, and the resulting image is actually bigger (200kb) because it does not have all the sophisticated (and slow) optimizations that your optimization software/site is using.
This unfortunately is beyond our control. If you are really concerned about the size of your images, you will need to perform all manipulations yourself (size, color, etc), then optimize, then use the image without any media manipulations.