protected function _beforeToHtml()
    {
        Mage::helper('ecomdev_varnish')->setIsEsiUsed(true);
        $handles = implode(',', $this->_handles);
        $params = array(
            'handles' => $handles,
            'package' => Mage::getSingleton('core/design_package')->getPackageName(),
            'theme' => Mage::getSingleton('core/design_package')->getTheme('default') ?: 'default',
            'store' => Mage::app()->getStore()->getCode(),
            'block' => $this->getBlockName()
        );

        if ($this->getTtl()) {
            $params['ttl'] = (string)$this->getTtl();
        }

        if ($this->hasData('referrer') && !$this->getData('referrer')) {
            $params['filter_referrer'] = '1';
        }

        if ($this->hasData('cookies') && !$this->getData('cookies')) {
            $params['filter_cookies'] = '1';
        }

        $params['checksum'] = Mage::helper('ecomdev_varnish')->getChecksum($params);
        $params['_secure'] = Mage::app()->getStore()->isCurrentlySecure();

        $url = $this->getUrl('varnish/esi/handle', $params);

        // Replace http with https,
        // So varnish can process ESI requests correctly and take domain name into account
        if (strpos($url, 'https://') === 0) {
            $url = 'http:' . substr($url, 6);
        }

        $this->setBlockUrl($url);
        $this->setHtmlId($this->getBlockAlias() . '-placeholder');
        
        return parent::_beforeToHtml();
    }