1

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?

1 Answer 1

1

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.

1
  • Thanks for the input, was not aware of most of the things you mentioned. Apr 27, 2018 at 7:21

Your Answer

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

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