croxton / imgixer

Generate Imgix URLs in Craft 3
MIT License
11 stars 4 forks source link

Does imgixer purge assets if they change in the back-end? #11

Closed terryupton closed 1 year ago

terryupton commented 1 year ago

Hey @croxton - is there any functionality built in, or any way to handle if you change/edit an asset in the back-end that it would purge this from Imgixer? For example, if I flipped an image n the craft image editor. I am not seeing this update the asset on the front-end. Thanks.

croxton commented 1 year ago

Not currently. Imgixer adds a last-modified timestamp to the query string in the image request - which also alters the signature hash - which works reliably as a cache-breaker using Servd as a provider. However Imgix and Imagekit use their own cache of the original image if it was previously requested. They should both respect the new timestamp, but in practice it only breaks the cache some of the time. Both services provide a way to purge the cache using an API call, however they actually recommend changing the filename so that all potential cache layers serve the updated asset.

From the Imgix docs:

To absolutely ensure compliance for an updated asset, it is best to give the asset a new path by renaming the file. Purging an asset is only recommended when absolutely necessary. https://docs.imgix.com/setup/purging-assets

This is nonetheless the solution other image plugins take, but so far I've avoided going down this route because it seems like a half-solution.

Currently I ask editors to 'Save as a new asset' after editing images, but I'm planning to look into a way to automate the filename change using Element::EVENT_AFTER_SAVE.