Question

I have created a data layer for google tag manager purposes. Currently, it is being loaded on every page. I am concerned about it increasing the pages load time.

For example, I'm looping through customer orders:

   $orderCollection = Mage::getResourceModel('sales/order_collection')
        ->addFieldToSelect('*')
        ->addFieldToFilter('customer_id', $customer->getId())
        ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->setOrder('created_at', 'desc');

        foreach ($orderCollection as $_order){
            $payment_method[] =  $_order->getPayment()->getMethodInstance()->getTitle();
            $shipping_method[] = $_order->getShippingMethod();
        }

Should I be worried about this slowing down my site for customers?

Was it helpful?

Solution

I'd say you should test the loading time with and without your code. Probably it's not more than a couple milliseconds. The bigger disadvantage with your approach is that you cannot use a full page cache or reverse proxy like varnish as your HTML is different for every customer. A better solution would be to receive this information via AJAX from your own customer controller and then store it in the local storage via Javascript. This way, it will only be loaded once (and asyncronously, it will not block loading the rest of the page if done correctly) per customer and not on every page load. Of course you have to take care to clear the local storage on login and on checkout.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top