Is there any way to access custom data stored in a customer session from a JS file ( without Ajax call ).

Here is the code for controller:


namespace Company\Vendor\Controller\Index;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Customer\Model\Session;

class Index extends Action
    protected $_customerSession;

    public function __construct(
        Context $context,
        Session $customerSession
    ) {
        $this->_customerSession = $customerSession;

    public function execute()

To access the MyValue value, we can use $this->_customerSession->getMyValue();

How can I get the MyValue value in a JS file?

1 Answer 1


[Not sure it's the correct way or best way] We need to set uncacheable page (will impact the performance). This is because when enabling the full page cache, the customer session will be clear.

  • Thanks for your answer but as you said it will impact the performance :|
    – vedu
    Apr 10, 2018 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.