Skip to content

Magento 2.1.2 Private Scope Blocks Caching #7131

Closed
@rob1256

Description

@rob1256

Preconditions

  1. Magento 2.1.2
  2. PHP 7
  3. MySQL 5.6
  4. Nginx

Steps to reproduce

  1. Set $this->_isScopePrivate = true; in your block constructor (after parent::__construct())
  2. Load a page with the block displayed and FPC enabled
  3. Change the contents of your block
  4. Reload page

Expected result

  1. New block content displayed as content is AJAX'd in via /page_cache/block/render/

Actual result

  1. Cached content is still shown, unless you clear browser cache manually.

I was using this in my own project to show/hide a pop-up based on whether a cookie was present or not. Setting your block scope to private means that Magento will AJAX in the block content after the initial page load and replace some placeholder content with the actual content. While it does do this, it doesn't work fully because of the following line:
https://github.com/magento/magento2/blob/develop/app/code/Magento/PageCache/view/frontend/web/js/page-cache.js#L228

This is causing the browser to cache the response from the AJXA, thus nullifying the point of the private scope.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions