elgentos / magento2-clientside-cache
elgentos/magento2-clientside-cache
Elgentos Clientside Cache
Magento 2 Clientside Cache
Magento already had support for ESI blocks, this will add an easy way to replace page heavy or slow blocks and
load them asynchronous without much hassle.
Installation
composer require elgentos/magento2-clientside-cache
bin/magento setup:upgrade
Usage
The easiest way is to add the <block class="Elgentos\ClientsideCache\Block\Async" />
around the original block, and use the correct alias as="" so the original block knows how which getChildHtml to fetch.
layout/LAYOUT_HANDLE.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<!-- Just add the wrapper around the original block -->
<block class="Elgentos\ClientsideCache\Block\Async" as="moved-the-alias-name-to-here">
<block name="heavy-block-name" template="Magento_HeavySlowThingy::path/to/file.phtml"/>
</block>
<!-- Or if you have something existing which you don't want to touch or can the original XML -->
<!-- Create a wrapper block -->
<block name="topmenu_mobile-replacement" class="Elgentos\ClientsideCache\Block\Async"/>
<!-- Move the replacement into the orignal location, use before original block name when working with containers or as when working with blocks -->
<move element="topmenu_mobile-replacement" destination="topmenu_generic" before="topmenu_mobile"
as="topmenu.mobile"/>
<!-- Move the heavy block into into the wrapper -->
<move element="topmenu_mobile" destination="topmenu_mobile-replacement"/>
</body>
</page>
Limit handles
You can limit the handles within the Async wrapper. This increases the possibility to re-use requests.
An example would be menu's which are the same on every page.
layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<!-- This will only use the default handle -->
<block class="Elgentos\ClientsideCache\Block\Async" as="moved-the-alias-name-to-here">
<argument name="handles" xsi:type="array">
<item name="default" xsi:type="string">default</item>
</argument>
</block>
</body>
</page>
Features
- Fetch content async
- Group similar requests for handles into on one single request
- Evaluate Javascript
Javascript
If you want to make sure that your global functions or objects are available you need to make sure to assign them to global scope.
Some examples;
<script>
const someFunction = () => {};
// add
window.someFunction = someFunction;
// and for functions
function helloWorld() {}
// add
window.helloWorld = helloWorld;
</script>
Custom integration
It's also possible to do custom integration too.
Use clientsideCacheAsync which will return a Promise and will with a object for all blocks you requested.
clientsideCacheAsync(['block_name', 'other_block'], ['default', 'catalog_category_view']).then(results => console.log(results))
// {block_name: "", "other_block": ""}
clientsideCacheAsync(['another_block'], ['default', 'catalog_category_view']).then(results => console.log(results))
// {another_block: ""}
Special thanks
The module was created during the Hackthon before the Mage Unconference in Cologne.
Thanks to the team for organising another great event and for the Hackathon.
Author
No changelog yet
The vendor hasn't published a changelog. Tagged releases appear in the Versions tab.
Requires 2
| Package | Constraint |
|---|---|
| magento/framework | * |
| magento/module-page-cache | 100.4.* |
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge — a phpcs finding can't make a module incompatible.
Static analysis
Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.
PHPStan
Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases. Cell → details modal.
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
Unit tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Integration tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
More from elgentos
View vendorLink existing guest orders to newly created or existing customer based on e-mail address
Allows customers to enter a secondary email address to login with
Hide Mollie payment methods based on category
Turn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.