I recently run into a situation where we had a custom piece of code that needed a Form Key as soon as possible after page load.

However the first request to Magento doesn’t set the form_key cookie for first time visitors that land on a page that’s cached. Our KnockoutJS component, which was being loaded as early as possible, received an empty value when trying to read from windows.FORM_KEY or even document.cookie .

After some debugging I found out that the form_key cookie is being generated by the frontend using this script: vendor/magento/module-page-cache/view/frontend/web/js/page-cache.js

The solution was to make our KnockoutJS component depend on pageCache, essentially instructing RequireJS to not load our component until pageCache was first loaded.


I’ve been working with Infinite Scroll experiences for almost 10 years now. The first time was in December 2010, when I published the first commit of an open-source Magento 1 Infinite Scroll extension — that would become one of the most used Infinite Scroll extensions for Magento 1 with thousands of installations worldwide. Back then, Pinterest was making big waves with their fancy user-experience.

Five years later Magento 2 had just been released and we open-sourced a new Infinite Scroll extension for the new platform. It now has 64,600+ downloads and 33+ forks.

In this series I’ll share a few…

Gabriel Somoza

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store