Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization Detective should be disabled by default on post previews #1841

Closed
westonruter opened this issue Feb 3, 2025 · 1 comment · Fixed by #1848
Closed

Optimization Detective should be disabled by default on post previews #1841

westonruter opened this issue Feb 3, 2025 · 1 comment · Fixed by #1848
Assignees
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken

Comments

@westonruter
Copy link
Member

I just realized that the the logic in od_can_optimize_response() is accounting for Customizer preview (is_customize_preview()) but not post previews (is_preview()). It doesn't make sense to collect a URL Metric for a post that isn't fully published yet, so is_preview() should be added as a condition to:

$able = ! (
// Since there is no predictability in whether posts in the loop will have featured images assigned or not. If a
// theme template for search results doesn't even show featured images, then this wouldn't be an issue.
is_search() ||
// Avoid optimizing embed responses because the Post Embed iframes include a sandbox attribute with the value of
// "allow-scripts" but without "allow-same-origin". This can result in an error in the console:
// > Access to script at '.../detect.js?ver=0.4.1' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
// So it's better to just avoid attempting to optimize Post Embed responses (which don't need optimization anyway).
is_embed() ||
// Since injection of inline-editing controls interfere with breadcrumbs, while also just not necessary in this context.
is_customize_preview() ||
// Since the images detected in the response body of a POST request cannot, by definition, be cached.
( isset( $_SERVER['REQUEST_METHOD'] ) && 'GET' !== $_SERVER['REQUEST_METHOD'] ) ||
// Page caching plugins can only reliably be told to invalidate a cached page when a post is available to trigger
// the relevant actions on.
null === od_get_cache_purge_post_id()
);

@westonruter westonruter added [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken labels Feb 3, 2025
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2024 Feb 3, 2025
@westonruter westonruter moved this from Not Started/Backlog 📆 to To Do 🔧 in WP Performance 2024 Feb 3, 2025
@hbhalodia
Copy link
Contributor

hbhalodia commented Feb 5, 2025

Hi @westonruter, I would like to work on the issue and would give me a start on contributing to performance team. Can I work on the issue and raise the PR for the fix?

Update: I do have raised the PR for the issue, let me know if that works well.

Thank You,

@westonruter westonruter moved this from To Do 🔧 to Code Review 👀 in WP Performance 2024 Feb 5, 2025
@github-project-automation github-project-automation bot moved this from Code Review 👀 to Done 😃 in WP Performance 2024 Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken
Projects
Status: Done 😃
Development

Successfully merging a pull request may close this issue.

2 participants