Cache Header Appears on the Homepage But Not on All Product Pages

I can see the x-litespeed-cache: hit,litemage header on the homepage and catalog pages, but not on any product pages. Why?

Homepage:

Product page:

It is possible one of your layouts contains the string cacheable=“false”. If this is found in the default layout, it's likely the whole site won't be cached at all. If it appears in another layout, then a particular route (such as all product pages) won't be cached.

To see if this is happening in one of your layouts, ssh to the app folder of your Magento2 installation, and execute the following:

grep -r cacheable * | grep xml | grep -v js | grep false

You will see something similar to this:

code/Lof/RewardPoints/view/frontend/layout/rewardpoints_redeemcode_index.xml:                   <block class="Lof\RewardPoints\Block\Account\Dashboard\RedeemCode" name="rewards.redeemcode" template="account/dashboard/redeemcode.phtml" cacheable="false"/>
code/Lof/RewardPoints/view/frontend/layout/rewardpoints_transactions_index.xml:                 <block class="Lof\RewardPoints\Block\Account\Dashboard\Listing" after="customer_account_navigation_block" name="lrw.account.poitns" template="account/dashboard/listing.phtml" cacheable="false">
code/Lof/RewardPoints/view/frontend/layout/rewardpoints_settings_index.xml:                     <block class="Lof\RewardPoints\Block\Account\Dashboard\Notification" name="rewards.notification" template="account/dashboard/notification.phtml" cacheable="false"/>
code/Lof/RewardPoints/view/frontend/layout/rewardpoints_index_index.xml:                        <block class="Lof\RewardPoints\Block\Account\Dashboard\Summary" after="customer_account_navigation" name="lrw.account.summary" template="account/dashboard/summary.phtml" cacheable="false">
code/Lof/RewardPoints/view/frontend/layout/rewardpoints_index_index.xml:                        <block class="Lof\RewardPoints\Block\Account\Dashboard\Listing" after="rewards.account.summary" name="lrw.account.poitns" template="account/dashboard/listing.phtml" cacheable="false">
code/Lof/RewardPoints/view/frontend/layout/customer_account_index.xml:                  <block class="Lof\RewardPoints\Block\Account\Dashboard\Listing" before="customer_account_dashboard_info" name="lrw.account.poitns" template="account/dashboard/listing.phtml" cacheable="false">
code/Lof/RewardPointsBehavior/view/frontend/layout/catalog_product_view.xml:                    <block class="Lof\RewardPointsBehavior\Block\Buttons\Facebook\Like" name="lrw.fb.scripts" template="scripts.phtml" cacheable="false" />
code/Lof/RewardPointsRule/view/frontend/layout/catalog_product_view.xml:                        <block class="Lof\RewardPointsRule\Block\Product\View" after="product.info.review" cacheable="false" template="product/view/spendingrule.phtml"/>
code/Plumrocket/Newsletterpopup/view/frontend/layout/prnewsletterpopup_index_preview.xml:            <block class="Plumrocket\Newsletterpopup\Block\Preview\Template" name="prnewsletterpopup.preview" template="Plumrocket_Newsletterpopup::popup.phtml" cacheable="false">
code/Plumrocket/Newsletterpopup/view/frontend/layout/prnewsletterpopup_index_snapshot.xml:            <block class="Plumrocket\Newsletterpopup\Block\Preview\Template" name="prnewsletterpopup.preview" template="Plumrocket_Newsletterpopup::snapshot.phtml" cacheable="false">
code/Customweb/AuthipayCw/view/frontend/layout/authipaycw_customer_aliases.xml:         <block class="Customweb\AuthipayCw\Block\Customer\Aliases" name="authipaycw.customer.aliases" cacheable="false" />
code/Customweb/AuthipayCw/view/frontend/layout/authipaycw_customer_aliases.xml:            <block class="Magento\Customer\Block\Account\Dashboard" name="customer.account.link.back" template="account/link/back.phtml" cacheable="false"/>
code/Customweb/AuthipayCw/view/frontend/layout/authipaycw_externalcheckout_review.xml:                <block class="Magento\GiftMessage\Block\Cart\GiftOptions" name="checkout.cart.order.actions.gift_options" as="gift_options" template="Magento_GiftMessage::cart/gift_options.phtml" cacheable="false">
code/RealexPayments/HPP/view/frontend/layout/realexpayments_hpp_process_process.xml:        <block class="RealexPayments\HPP\Block\Process\Process" name="realexpayments-hpp-process-form" template="process/form.phtml" cacheable="false"/>
code/RealexPayments/HPP/view/frontend/layout/realexpayments_hpp_process_result.xml:        <block class="RealexPayments\HPP\Block\Process\Result" name="realexpayments-hpp-process-result" template="process/result.phtml" cacheable="false"/>
code/RealexPayments/HPP/view/frontend/layout/checkout_cart_index.xml:            <block class="RealexPayments\HPP\Block\Process\Result\Observe" name="realex.cart.observe" template="result/observe.phtml" cacheable="false"/>
code/RealexPayments/HPP/view/frontend/layout/realexpayments_hpp_cards_success.xml:            <block class="RealexPayments\HPP\Block\Cards\Success" name="customer.account.realexpayments.cards" template="cards/success.phtml" cacheable="false">
code/RealexPayments/HPP/view/frontend/layout/checkout_index_index.xml:            <block class="RealexPayments\HPP\Block\DeviceFinger\Tags" name="realex.checkout.devicefinger" template="devicefinger/tags.phtml" cacheable="false"/>
code/RealexPayments/HPP/view/frontend/layout/realexpayments_hpp_cards_redirect.xml:        <block class="RealexPayments\HPP\Block\Cards\Redirect" name="realexpayments-hpp-redirect-form" template="process/form.phtml" cacheable="false"/>
code/RealexPayments/HPP/view/frontend/layout/realexpayments_hpp_cards_view.xml:            <block class="RealexPayments\HPP\Block\Cards\View" name="customer.account.realexpayments.cards" template="cards/view.phtml" cacheable="false">
code/RealexPayments/HPP/view/frontend/layout/realexpayments_hpp_cards_result.xml:        <block class="RealexPayments\HPP\Block\Process\Result" name="realexpayments-hpp-process-result" template="process/result.phtml" cacheable="false"/>

You can analyze the code to determine that RealexPayments or Plumrocket won't cause your product pages to be uncacheable, but that Lof\RewardPoints will affect your product pages. This is because in the Magento 2 code structure, any route from view/frontend/layout/catalog_product_view.xml in any module will be combined together and loaded to every product page.

How do you figure this out?

Under the app folder, execute the following:

find . | grep 'layout/catalog_product_view.xml'

The result:

./code/Lof/RewardPoints/view/frontend/layout/catalog_product_view.xml
./code/Lof/RewardPointsBehavior/view/frontend/layout/catalog_product_view.xml
./code/Lof/RewardPointsRule/view/frontend/layout/catalog_product_view.xml
./code/WeltPixel/OwlCarouselSlider/view/frontend/layout/catalog_product_view.xml
./code/Vegvari/VovayatsyukAlsoviewedFix/view/frontend/layout/catalog_product_view.xml
./design/frontend/Meigee/fortress/Magento_Wishlist/layout/catalog_product_view.xml
./design/frontend/Meigee/fortress/Magento_Catalog/layout/catalog_product_view.xml

Then:

cd ../vendor/
root@server1 vendor]# find . | grep 'layout/catalog_product_view.xml'

The result:

./vovayatsyuk/magento2-alsoviewed/view/frontend/layout/catalog_product_view.xml
./magento/module-product-alert/view/frontend/layout/catalog_product_view.xml
./magento/magento2-base/dev/tests/integration/testsuite/Magento/Framework/View/Layout/_mergeFiles/layout/catalog_product_view.xml
./magento/module-checkout/view/frontend/layout/catalog_product_view.xml
./magento/module-google-optimizer/view/frontend/layout/catalog_product_view.xml
./magento/module-wishlist/view/frontend/layout/catalog_product_view.xml
./magento/theme-frontend-luma/Magento_Catalog/layout/catalog_product_view.xml
./magento/module-review/view/frontend/layout/catalog_product_view.xml
./magento/module-product-video/view/frontend/layout/catalog_product_view.xml
./magento/module-paypal/view/frontend/layout/catalog_product_view.xml
./magento/module-catalog-inventory/view/frontend/layout/catalog_product_view.xml
./magento/module-catalog/view/frontend/layout/catalog_product_view.xml
./magento/module-msrp/view/frontend/layout/catalog_product_view.xml

Any catalog_product_view.xml in the above list will take effect for every page. The only module to appear in either of the above lists as well as the original search for cacheable is Lof/RewardPoints.

Hence we have identified the cause of the problem. It is code/Lof/RewardPointsBehavior/view/frontend/layout/catalog_product_view.xml, which contains:

<block class="Lof\RewardPointsBehavior\Block\Buttons\Facebook\Like" name="lrw.fb.scripts" template="scripts.phtml" cacheable="false" />

While you can simply back up the original XML and change cacheable=“false” to cacheable=“ true”, please be aware that this solution may not work for every situation. You run the risk of breaking some part of your store, if you are not careful. To err on the side of caution, you may wish to engage our experienced Magento Developer for such troubleshooting.

  • Admin
  • Last modified: 2017/11/14 19:07
  • by Lisa Clarke