How to enable profiler in magento2

To enable the profiler we can add it from index.php or apache/nginx conf file.

Enable Profiler from index.php:

  1. Open {magento root}\pub\index.php from magento2
  2. Add following line from the file $_SERVER[“MAGE_PROFILER”]=”html”;
  3. Clear cache you can able to see the profiler.


Enable profiler from apache conf or magento2 .htaccess :

Flash Catalog Images Cache Magento2

To flash the Catalog Images cache, first of all instantiate the Object and Event Manager in your constructor


private $objectManager;
private $eventManager;

public function __construct(
    \Magento\Framework\ObjectManagerInterface  $objectManager,
    \Magento\Framework\Event\Manager $eventManager
     $this->objectManager = $objectManager;
        $this->eventManager = $eventManager;

After that you can clean the catalog images cache by using this two code lines

Magento2 gallery afterLoad callback

If you need to do any JavaScript  code after Magento gallery is loaded you can use this event in your code

<script type="text/javascript">
    require(['jquery', 'mage/gallery/gallery'], function($, gallery){
        $('[data-gallery-role=gallery-placeholder]').on('gallery:loaded', function () {
          // write your code here

it is the best code that i used, I hope this will help you


Magento2 Refresh Cache for Single Product

You can use this code to refresh the cache for single product

$objectManager =   \Magento\Framework\App\ObjectManager::getInstance();
$productR =      $objectManager ->create('\Magento\Catalog\Api\ProductRepositoryInterface');
$product = $productR->get('product_sku');
$this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $product]);

Please initialize the objectManager and ProductRepository in your constructor

Subscribe to magento2