• Resolved jumbo

    (@jumbo)


    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:

    1. In Gutenberg editor, add an image to a post.
    2. You’ll notice that upon saving the post, the proper, non-CDN, home/site URL is used.
    3. Resave the page and you’ll still notice the proper, non-CDN is used.
    4. So far, so good.
    5. Now, change the image “resolution” from large to medium (or any other size) and resave the post.
    6. 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:

    1. 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.
    2. 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mustafa Uysal

    (@m_uysl)

    Hi @jumbo,

    Good catch again!

    Expected behavior: Always save the non-CDN site URL in the database for images (and other files) when updating a post or page.

    Absolutely! DB should be the source of truth and hold the unmodified resource address.

    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.

    I’ve identified that the issue stems from the block editor fetching image details via an API call, which appears to be the primary cause of this problem.

    I’m working on the fix and definitely will be fixed in the next version.

    Thank you once again for your comprehensive bug report. Your input is greatly appreciated.

    Plugin Author Mustafa Uysal

    (@m_uysl)

    Hi @jumbo,

    This problem has been fixed in version 3.3.2. Please update and let me know if the problem persists.

    If you are happy with Powered Cache overall, it would be great if you could leave a review here ??

    Thanks!

    Thread Starter jumbo

    (@jumbo)

    Hi @m_uysl

    Everything is working great now. Thanks. I just left a review.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Changing image size/resolution in Gutenberg editor saves CDN URL in database’ is closed to new replies.