Skip to content

Prevent Cache-Control: max-age=300 header on dynamic pages (e.g. WooCommerce cart/checkout) #1082

Description

@pirate-bot

Impact: 90 · Confidence: 100 · Complexity: 20

Description

Problem:
While optimizing images on the fly, Optimole outputs header( 'Cache-Control: max-age=300' ) indiscriminately. On server setups like Nginx that respect these headers, this forces caching on highly dynamic and sensitive pages such as WooCommerce Cart and Checkout, directly breaking e-commerce functionality and potentially displaying other customers' carts.

Desired Behavior:
Optimole must intelligently decide whether it is safe to emit cache-control headers rather than doing so blindly. It should back off if standard WP non-cacheable signals are detected.

Acceptance Criteria:

  • The header injection logic must check for the DONOTCACHEPAGE constant and skip header injection if it is true.
  • Include built-in exclusions for standard dynamic endpoints like WooCommerce Cart, Checkout, and My Account.
  • Implement a PHP filter (e.g., optml_disable_temporary_cache_header) so developers can easily bypass this functionality contextually.

Customer Context

A Business-tier customer utilizing Nginx caching discovered that their WooCommerce Cart and Checkout pages were being improperly cached. They traced the issue in the code to Optimole explicitly sending a 5-minute Cache-Control header while optimizing newly requested images. They are urgently asking for a way to disable this to prevent their checkout flow from breaking.

Root Cause Analysis

The root cause is not the lack of a toggle, but rather that Optimole applies a caching header to all pages globally when an image optimization process is triggered. Because e-commerce pages (like Cart/Checkout) absolutely rely on bypassing server page caching to process transactions and display user-specific data, forcefully applying this cache header compromises the broader site architecture. The underlying need is a reliable checkout flow free from unintended proxy/server caching.

Alternative Suggestions

Instead of building a new UI setting in the Optimole dashboard to disable the header, improve the existing behavior by automatically respecting WordPress's DONOTCACHEPAGE constant and WooCommerce endpoints, acting as a better default. Optionally, add a simple developer filter for custom exclusions. This solves the core caching issue seamlessly for the vast majority of e-commerce users without adding configuration bloat.

Reasoning

The customer found that Optimole unconditionally injects a Cache-Control: max-age=300 header while optimizing images, which inadvertently instructs their Nginx server to cache WooCommerce checkout and cart pages, breaking e-commerce functionality. While the customer asks for a way to turn this off (implying a new setting), the best approach is to improve the existing logic: the plugin should have better defaults that respect standard WordPress caching constants (DONOTCACHEPAGE) and automatically avoid setting cache headers on known dynamic pages, along with a simple developer filter.


Source: HelpScout #3364439372
Generated by feature-request-triage workflow (ID: feature-request-triage_6a3a8368710457.46333969)

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Improvement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions