What Statamic’s SAVE_CACHED_IMAGES really does

I think I got SAVE_CACHED_IMAGES in Statamic wrong the whole time. I thought it's about whether Glide-generated images are kept when clearing caches. If got it right, this is what it really does:

  • when set to true
    • All image presets defined in assets.php will be generated on upload
    • All Glide image variants referenced on a page will be generated on initial page load
    • All Glide variants required anywhere will be generated when waming the static cache
    • Image variants are stored in /public/img/containers/
  • when set to false:
    • All image presets defined in assets.php will still be generated on upload
    • Only the images requested by the browser will be generated and cached
    • Image variants are stored in /storage/statamic/glide/containers

Generated Glide variants are never wiped by clearing the application cache, no matter how SAVE_CACHED_IMAGES is set.

Consequences

Setting SAVE_CACHED_IMAGES to false

  • Will make initial loading times for pages with new images faster, because only the image in the format and resolution as requested by the browser will be generated (and cached for subsequent requests), not all sizes and formats referenced in markup
  • Uploading new imges in the panel will be faster because asset presets won’t be generated
  • Less storage will be needed, because when set to true lot’s of images are generated and potentially never used

Glide Cache

  • when setting SAVE_CACHED_IMAGES to false, image variants are still cached within Glide’s cache system, located at /storage/statamic/glide/containers
  • Glide’s cache is only cleared when running php please glide:clear, not with the regular php please cache:clear

Potential Disadvantages of setting SAVE_CACHED_IMAGES to false

URLs to images will not contain a file extension. In case of GLightbox, this leads to the script “thinking” the target URL is a page to embed within an iFrame instead of directly showing it.

Update: In case of GLightbox this can be solved by adding the data-type="image" attribute to the link that points to the large image

Caveats

When changing an existing project with static caching to SAVE_CACHED_IMAGES=false, it might seem like having no effect at all. Statamic will build static pages with URLs to saved cached images if they're still present. Only after deleting public/img/containers/<name-of-container> , I started noticing images being served from URLs like /img/asset/<hash>

This Statamic setting is surprisingly confusing. I might well be wrong with some of my observations and would be glad to be corrected if so.