Https + Magento Cache + Internet Explorer = No image

Magento uses by default an advanced cache system in order to display templates content faster. But default configuration of this cache can sometime creates some issues.

Recently, we had some images that were not displayed in the top menu when we switch from an http page to a https page using Internet Explorer browser. Images in this menu still have a non secured (http) URI. Internet Explorer is not pleased with such content. By default, this browser does not display unsecured content on a secured page. We have this security warning displayed when some image have http URI on a https page:

Internet Explorer Security Warning

Block displaying top menu was using cache system but this cache was not regenerated when we switch from a http to a https page. That's why images were still having http URI.

For fixing this problem, we must rewrite getCacheKey method from Mage_Catalog_Block_Navigation class. A new parameter telling if page use http or https should be included in cache key. Cache will then be different for this 2 types of pages. This parameter is added with getSkinUrl method

Default code of getCacheKey

public function getCacheKey()
{
    return 'CATALOG_NAVIGATION_' . Mage::app()->getStore()->getId()
        . '_' . Mage::getDesign()->getPackageName()
        . '_' . Mage::getDesign()->getTheme('template')
        . '_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
        . '_' . md5($this->getTemplate() . $this->getCurrenCategoryKey());
}

is then replaced by following code

public function getCacheKey()
{
    return 'CATALOG_NAVIGATION_' . Mage::app()->getStore()->getId()
        . '_' . Mage::getDesign()->getPackageName()
        . '_' . Mage::getDesign()->getTheme('template')
        . '_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
        . '_' . md5($this->getTemplate() . $this->getCurrenCategoryKey())
        . '_' . md5($this->getSkinUrl()); /*** FIX IN THIS LINE ***/
}

This is it. You can now use peacefully https on Internet Explorer.

For more details about Magento cache system you can read this article.

11 comments on "Https + Magento Cache + Internet Explorer = No image"

Ben's picture
Ben (visitor) - Thu, 22/04/2010 - 13:45:

I tried to use the fix that I suggested to you and I get a php error:

I inserted:

. ‘_’ . md5($this->getSkinUrl());

in public function getCacheKey

and got

Parse error: syntax error, unexpected ‘.’ in /var/www/vhosts/mysite.co.uk/httpdocs/app/code/core/Mage/Catalog/Block/Navigation.php on line 66

Laurent Clouet's picture
Laurent Clouet - Tue, 27/04/2010 - 12:53:

Hi Ben,

I think that you just probably forgot to remove semicolon (;) in line 65 and put it in line 66.

Laurent

J.T.'s picture
J.T. (visitor) - Thu, 10/06/2010 - 15:43:

Thanks. I referenced your code suggestion in these two threads:

http://www.magentocommerce.com/boards/viewthread/7894/

http://www.magentocommerce.com/boards/viewthread/193429/

In Mage 1.3 you add this line:


$key.= md5($this->getSkinUrl()); //Fix for http vs https caching problem explained on http://blog.baobaz.com/en/blog/https-magento-cache-internet-explorer-no-...

Complete function:


public function getCacheKey()
{
$key = Mage::app()->getStore()->getId().'_CATALOG_NAVIGATION' . md5($this->getTemplate());
$key.= md5($this->getCurrenCategoryKey());
$key.= Mage::getSingleton('customer/session')->getCustomerGroupId();
$key.= md5($this->getSkinUrl()); //Fix for http vs https caching problem http://blog.baobaz.com/en/blog/https-magento-cache-internet-explorer-no-...
return $key;
}

I hope Varien fix this as I don't like hacking core files and find it too annoying a bug to make a module to override the class.

Ankit Sharma's picture
Ankit Sharma (visitor) - Thu, 17/06/2010 - 07:03:

Thanks.
It solved the problem for menu images.
But its still now showing the checkout images, any solution?

tuba's picture
tuba (visitor) - Fri, 16/07/2010 - 23:48:

does anybody fixed this in 1.4, I still could not make it work

Lacey's picture
Lacey (visitor) - Wed, 08/12/2010 - 09:35:

Hey guys, I ammended the code to look like the code I have. This is the code I found in the file he mentions:
-----------------------------
public function getCacheKeyInfo()
{
return array(
'CATALOG_NAVIGATION',
Mage::app()->getStore()->getId(),
Mage::getDesign()->getPackageName(),
Mage::getDesign()->getTheme('template'),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
'template' => $this->getTemplate(),
$this->getCurrenCategoryKey()
);
}
--------------------------
If your code looks like that, replace it with this:
--------------------------
public function getCacheKeyInfo()
{
return array(
'CATALOG_NAVIGATION',
Mage::app()->getStore()->getId(),
Mage::getDesign()->getPackageName(),
Mage::getDesign()->getTheme('template'),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
'template' => $this->getTemplate(),
$this->getCurrenCategoryKey(),
$this->getSkinUrl()
);
}
----------------------------
Fixed my error! :o)

Lacey's picture
Lacey (visitor) - Wed, 08/12/2010 - 09:37:

PS: I am on 1.4.1. Dont forget to to copy this file in the local Mage_Catalog_Block_Navigation :)

Joe's picture
Joe (visitor) - Sat, 05/02/2011 - 05:24:

I'm running on 1.4.0.1 and had the same problems as above. I'm running the absolute free theme.

Tools -> Configuration -> Advanced -> Developer -> CSS Settings

Merge CSS Files (beta) - Set this to No.
It says "Experimental. Turn this feature off if there are troubles with relative urls inside css-files."

I turned it off and all my https secure and unsecure mixed images went away. All the background, buttons, etc. are in the CSS files as relative paths.

Hope this helps someone.

Mick O'Hea's picture
Mick O'Hea (visitor) - Tue, 08/02/2011 - 23:50:

Joe, brilliant. That solved it for me too. Thanks.

Anonymous's picture
Anonymous (visitor) - Mon, 28/02/2011 - 23:20:

Fantastic!! This worked straight away for me after spending the whole day trying to figure it out.
Were on 1.4.1 and works perfectly. All secure and green padlock shining away securely!

Thank you

Nicolas's picture
Nicolas (visitor) - Sat, 26/03/2011 - 03:07:

Did not work for me.... :-(
I am using 1.4.1.1