Changing image size/resolution in Gutenberg editor saves CDN URL in database
-
Once again, thanks for this great plugin.
Expected behavior: Always save the non-CDN site URL in the database for images (and other files) when updating a post or page.
Current behavior: When the CDN setting is enabled, any change to an image’s size in Gutenberg editor will save the CDN URL in the database (i.e., table: wp_posts, column: post_content) instead of the regular site URL.
Steps to reproduce:
- In Gutenberg editor, add an image to a post.
- You’ll notice that upon saving the post, the proper, non-CDN, home/site URL is used.
- Resave the page and you’ll still notice the proper, non-CDN is used.
- So far, so good.
- Now, change the image “resolution” from large to medium (or any other size) and resave the post.
- You’ll now notice the CDN version of the URL has been saved in the database.
I want to clarify that the CDN URL is getting transparently switched in Gutenberg even before the post is saved.
For instance, if you add an image (which WordPress defaults to “large”) then, switch it to “medium”, and save the page, the post will save with the medium URL pointing to the CDN.
But if you were to add a brand new image, let it default to “large”, the save the post, the CDN hostname would not be saved in the database. Which is the preferred behavior. Even resaving the page keeps the proper original URL intact. The switch only takes place when the size changes in the sidebar.
So this action is taking place before any initial save.
Two problems with this approach:
- If the CDN hostname ever changed, it wouldn’t affect older posts that hardcoded the old CDN URL for those images, causing the images to break.
- Editing posts within the Gutenberg editor will now display the CDN URL within Gutenberg to the editor/admin. This disrupts image optimization plugins, such as ShortPixel Image Optimizer, which compresses images upon upload, but since the CDN hostname switch is taking place while editing in Gutenberg, the original, unoptimized image gets pulled into the CDN cache too soon. There’s a race condition taking place, which Gutenberg and Powered Cache will always win. And I think it makes sense that CDN URLs should never appear anywhere within the admin interface, Gutenberg, or make their way into the database.
Thanks.
- The topic ‘Changing image size/resolution in Gutenberg editor saves CDN URL in database’ is closed to new replies.