If you cache modules then the cache of those modules will include all custom head elements (ie, elements added via addCustomTag()), even if they aren't associated with that module. This will then cause those custom head elements to be added to other pages inappropriately.
Here is what let me to this:
After clearing my site's cache and loading an article, then a second article, that second article has some of the head elements that belonged to the first article (when viewing the source). If I visit a third article then that article will have some of the head elements from both the first and the second article.
Turning off cache makes the issue go away. This happens from both Conservative caching and Progressive caching.
When I looked through the files in my /cache/ folder I discovered the extra head elements that were being added were all part of module cache files (files in "/cache/mod_custom/" for example). Turning off caching for all modules (via the modules' Advanced Options parameters) also makes the issue go away.
I then researched why modules were storing head elements that had nothing to do with that module (eg, a mod_custom module's cache was storing addCustomTag() elements from a content plug-in). I found in:
/libraries/joomla/application/module/helper.php -> moduleCache() :
line 420:
Code: Select all
$wrkaroundoptions = array (
'nopathway' => 1,
'nohead' => 0,
'nomodules' => 1,
'modulemode' => 1,
'mergehead' => 1
);
/libraries/joomla/cache/cache.php -> setWorkarounds()
line 529:
Code: Select all
if ($loptions['nohead'] != 1) {
$cached['head'] = $document->getHeadData();
if ($loptions['modulemode'] == 1) {
unset($cached['head']['title']);
unset($cached['head']['description']);
unset($cached['head']['link']);
unset($cached['head']['links']);
unset($cached['head']['metaTags']);
}
}
When that module's cache is read (when another page is loaded) the 'mergehead'=>1 causes the cached custom head elements from the module to be added to the page's head (de-dupping any identical elements). Therefore, changing 'nohead'=>0 to 'nohead'=>1 causes this issue to go away. This is isn't a solution though, because this would cause fatal issues for any module that's use custom head elements (I didn't test this statement it though).
Am I right in seeing this as a bug or am I missing something? For now I have turned off cache for all modules.
Reported on:
Joomla! 1.7.3 Stable [ Ember ] 14-Nov-2011 14:00 GMT
Platform 11.2.0 Stable+Modified [ Omar ] 27-Jul-2011 00:00 GMT
Affected functions:
Module Caching
Related files:
/libraries/joomla/application/module/helper.php
/libraries/joomla/cache/cache.php
/libraries/joomla/document/html/html.php