Page 1 of 1

Joomla file cache javascript duplication bug

Posted: Thu May 24, 2012 11:34 am
by jshed
I have Joomla File cache turned on (Global Configuration not the cache plugin) and on initial load after the cache is cleared everything is fine, then on reload the javascript that is added to the head by doc->addScriptDeclaration (JS code not JS link) is duplicated. So the first module's cache file includes just its JS, then all subsequent modules include all JS from previous modules as well as its own. Therefore I get lots of JS duplication as follows:
<script type='text/javascript'>
Module1 JS
Module1 JS
Module2 JS
Module1 JS
Module2 JS
Module3 JS
Module1 JS
Module2 JS
Module3 JS
Module4 JS
</script>

Anyone know how to resolve this?

Re: Joomla file cache javascript duplication bug

Posted: Wed May 30, 2012 7:05 am
by gboul
I see the same behavior. Actually it starts with a few duplications and as time passes (possibly other users load the page) the duplication increases to many times. ( have counted up to 12 repetitions).
I had to stop the cache, since the javascript on my pages wasn't working.
I have installed Joomla 2.5.4 with VM 2.0.6 and Gantry Framework.

Re: Joomla file cache javascript duplication bug

Posted: Thu May 31, 2012 3:13 pm
by gboul
I found out that the problem exists only for the modules that are not cached and only when a user is not logged in.

Re: Joomla file cache javascript duplication bug

Posted: Tue Jun 05, 2012 7:45 am
by rizor
I have the same issue or something very similar, I'm using the Warp framework on a fairly complex website.
The scripts added with $document->addScript() are fine, only the snippets added with addScriptDeclaration() duplicate. This happens for both cached and uncached modules, and also for plugins.
1) the headers will be not be duplicated with:

Code: Select all

$document->addScript()            
$document->addStyleSheet()
JHTML::script()                            
JHTML::stylesheet(
2) but they will be duplicated with:

Code: Select all

$document->addScriptDeclaration() 
$document->addStyleDeclaration()
Moreover, if you have multiple hostnames for the same Joomla installation, and inadvertedly included the stylesheets or scripts with the full address (using JURI::base or JURI::path), they will be duplicated too across domains, so you'll end up with

Code: Select all

<script src="http://host1.your-domain.com/modules/mod_test/js/script1.js" ...
<script src="http://host2.your-domain.com/modules/mod_test/js/script1.js" ...
Workarounds:
a) Check your page source for any script or style with full path (i.e. script src="http://your-host.net/modules/mod_test/js/script.js"), which should be generated by

Code: Select all

JHTML::script('script.js',JURI::base().'modules/mod_test/js/');
and simply remove the JURI::base().

b) Move the scripts you insert "on the fly" to the template file. This will require some coding to tell the template when it should be including the scripts.

Where is the problem?
I have thouroghly studied the JCache documentation, particularly on docs.joomla.org and http://www.bzzzz.biz/blog/joomla/joomla ... es-2.bzzzz at the Workarounds paragraph.

While templates and joomla can do a nice job or removing duplication of included scripts and styles, it's really beyond their scope to check for duplicate script snippets (in fact, it could even be undesirable (i.e. when including google pageads, you will have intentional duplicate scripts).

The test 1
Setup: global cache enabled + system cache plugin disabled.
I cleared the cache and loaded a page twice where a content plugin inserts code with addScriptDeclaration().
First time, all fine;
Second time, the headers get duplicated.
The test 2
Setup: global cache enabled + system cache plugin enabled.
Duplication occurs only when surfing across pages, not reloading the same one (if it was cached correctly the first time!)

The issue is that the headers most often get duplicated from the cache!!! Notice the timestamp it has the same exact time on three occurences. This is the result of browsing and/or reloading 10 pages on the site.

Code: Select all

  <script type="text/javascript">
function testMe() {
// XXXXXXXXXthis is a test script for duplication 1338881820 
var aTest = '09:37:00.000000';}

	window.addEvent('domready', function(){ $$('dl.tabs').each(function(tabs){ new JTabs(tabs, {}); }); });
function testMe() {
// XXXXXXXXXthis is a test script for duplication 1338881124 
var aTest = '09:25:24.000000';}

	window.addEvent('domready', function(){ $$('dl.tabs').each(function(tabs){ new JTabs(tabs, {}); }); });
function testMe() {
// XXXXXXXXXthis is a test script for duplication 1338881124 
var aTest = '09:25:24.000000';}

	window.addEvent('domready', function(){ $$('dl.tabs').each(function(tabs){ new JTabs(tabs, {}); }); });
function keepAlive() {	var myAjax = new Request({method: "get", url: "index.php"}).send();} window.addEvent("domready", function(){ keepAlive.periodical(3600000); });
function testMe() {
// XXXXXXXXXthis is a test script for duplication 1338881124 
var aTest = '09:25:24.000000';}

Again, this happens with the Warp framework. I am guessing Gantry gets something wrong in the headers cache management too.
Using beez20, there is no way I could get duplicate headers after 10 reloads of different pages.

Re: Joomla file cache javascript duplication bug

Posted: Mon Jun 18, 2012 1:50 pm
by stutteringp0et
I posted this issue in the GitHub joomla-platform issues list 6 months ago - they're still discussing it.

https://github.com/joomla/joomla-platform/issues/673

Re: Joomla file cache javascript duplication bug

Posted: Sat Dec 08, 2012 7:35 am
by qvsoft
I still get this problem with joomla 2.5.8.
How to fix it?

Re: Joomla file cache javascript duplication bug

Posted: Sat Mar 16, 2013 1:56 am
by gubagy
The same with Joomla! 2.5.9
Someone workaround ?

Thanks in advance !

Greetz Guby

Re: Joomla file cache javascript duplication bug

Posted: Sat Mar 16, 2013 2:16 am
by stutteringp0et
Per Louis Landry: "I'm going to close the issue, and if any of you want to take a crack at a pull request to fix this please feel free. Again, I'd be happy to review it."

The issue I opened on GitHub was closed with no resolution and the message was (basically) "fix it yourself"

Look 3 posts up to see the link to the GitHub issue that I opened.

Re: Joomla file cache javascript duplication bug

Posted: Wed Apr 10, 2013 8:12 am
by jiggo
Hi,

I've got the same issue with a custom plugin I made which includes some js "inline". Progressive Cache makes inline declarations loaded twice!!

Did any of you guys solve this issue?

jiggo

Re: Joomla file cache javascript duplication bug

Posted: Wed Apr 10, 2013 12:34 pm
by stutteringp0et
I've rewritten my extensions to use JS classes that are loaded with domready statements. The vars are passed with objects set to window vars. With this method, the only thing that gets duplicated is the window var.

Have a look at my "Top of the Page" plugin to see how I'm doing it.

Re: Joomla file cache javascript duplication bug

Posted: Sun Apr 14, 2013 10:46 am
by Rezayusefi
stutteringp0et how can i cache JS in joomla?

Re: Joomla file cache javascript duplication bug

Posted: Sun Apr 14, 2013 4:34 pm
by stutteringp0et
the object of this thread is not to cache JS.

Basically, a joomla bug causes any script added by JFactory::getDocument()->addScriptDeclaration('...') to be cached and served to subsequent pages, even doubled or tripled on the same page. It's ridiculous, and apparently unavoidable.

Re: Joomla file cache javascript duplication bug

Posted: Sun Jun 09, 2013 10:20 am
by keh
This js duplication bug seems in some way related to moving a joomla install between two different servers or between folders on same server. To solve it I made a fresh re-install of joomla on the "live" domain (that had the duplication bug) on a new db. Then I connected my "old" db to the fresh install and the duplication bug is gone...

Re: Joomla file cache javascript duplication bug

Posted: Sun Jun 09, 2013 3:30 pm
by stutteringp0et
this is related to cache

Re: Joomla file cache javascript duplication bug

Posted: Sun Jun 09, 2013 3:54 pm
by keh
stutteringp0et wrote:this is related to cache
Yes. I read the header ;)

The joomla file cache javascript duplication bug I had came from copying joomla installs to another location. I tested with to different servers setups.

Re: Joomla file cache javascript duplication bug

Posted: Thu Oct 10, 2013 12:09 pm
by creativedotit
Problem still persist in current Joomla 2.5.x and 3.x....

After 12 hours of hard debugging I found the real cause of the problem and I've made a patch and submitted it to Joomla github
(but it wasn't reviewed/approved yet)

If you want to try it:
https://github.com/joomla/joomla-cms/pull/2150/files
Please report if it works (it does for me and I've applied it to many Joomla cache enabled sites in production without any drawback)