Universal version component in URL to fetch the last version of file from CDN
Hi.
In our project we have a function to replace an existing file with a new one with keeping the file URL. In our case, it is important not to change the link and it is desirable to quickly fetch a new version of the file on this link. I am aware of the possibility to invalidate the previous version throughout the CDN when uploading a file with existing public_id. But it could take a long time.
Is it possible to use the universal version component in the URL to fetch the last version of file from CDN? For example something like this: https://res.cloudinary.com/demo/image/upload/vLastVesrion/sample.jpg
-
Hi Freddy,
Please note that there are three possible URL formats we can send for invalidation at the CDN, and these are outlined here: https://support.cloudinary.com/hc/en-us/articles/360001208732-What-URL-conventions-are-invalidated
Invalidation requests are sent when you delete or overwrite an image using our Media Library UI, or when you use the SDK/API, and also provide the 'invalidate' parameter, set to 'true'.
By default, all accounts send invalidations for the default format of URL which our SDK produces, which uses no version number for assets in the root of your account, and a 'v1' placeholder for assets in folders (option 1 from the URL above).
Your account is currently configured using the default settings (option 1 from the list above) which means for assets in the root of the account it will invalidate the URL without a version number, while URLs in folders like in this case, would invalidate the URL with a 'v1'.
You can continue to use the current URL format (option 1) and if you're already using our helper SDK methods for generating the URLs then this may be the best approach as it won't require any updates on your side. The CDN will already invalidate this URL format as it's what the default configuration on the account is set to.
On the other hand, if you're creating the URLs manually and not using the helper methods, then what might be easier for you is if you use no version component (option 2) for both assets in folders and in the root of your account. If this is something you'd like then please let me know and I can go ahead and configure your account to invalidate this specific URL format.
When combined with the invalidate flag on re-uploads the same URL will be serving the newest image if you're requesting the image with the URL format that the account is configured to invalidate. The CDN invalidation is quick and will be done within seconds in the vast majority of cases so there shouldn't be any concerns regarding the time taken.
Please let me know your thoughts.
Best regards,
Aleksandar
-
Hi Aleksandar,
Thanks for your response. I think we'll try to use the default settings. I thought that cache invalidation is long operation because I used URLs without version component for assets in folders. I checked the work of cache invalidation with URLs that contain 'v1' placeholder - it works. Thanks for your help.
-
You're welcome, Freddy.
Yes, when your assets are within folders based on the current account configuration for invalidation you should use 'v1' as the version component and you'll be able to use the same URL when overwriting an asset. Similarly, if you have any assets in the root of your account then you should use no version component in the URLs as this URL format will be invalidated for assets in the root folder.
Post is closed for comments.
Comments
4 comments