Joomla file cache javascript duplication bug

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
jshed
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Oct 25, 2011 8:31 am

Joomla file cache javascript duplication bug

Post by jshed » Thu May 24, 2012 11:34 am

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?

gboul
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed May 30, 2012 6:58 am

Re: Joomla file cache javascript duplication bug

Post by gboul » Wed May 30, 2012 7:05 am

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.

gboul
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed May 30, 2012 6:58 am

Re: Joomla file cache javascript duplication bug

Post by gboul » Thu May 31, 2012 3:13 pm

I found out that the problem exists only for the modules that are not cached and only when a user is not logged in.

User avatar
rizor
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Thu Feb 11, 2010 8:59 am
Location: Roma, italy
Contact:

Re: Joomla file cache javascript duplication bug

Post by rizor » Tue Jun 05, 2012 7:45 am

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.

User avatar
stutteringp0et
Joomla! Ace
Joomla! Ace
Posts: 1389
Joined: Sat Oct 28, 2006 11:16 pm
Location: Texas
Contact:

Re: Joomla file cache javascript duplication bug

Post by stutteringp0et » Mon Jun 18, 2012 1:50 pm

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
My extensions: http://extensions.joomla.org/profile/pr ... ails/18398
Honk if this signature offends you.

qvsoft
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Wed Apr 15, 2009 7:22 am

Re: Joomla file cache javascript duplication bug

Post by qvsoft » Sat Dec 08, 2012 7:35 am

I still get this problem with joomla 2.5.8.
How to fix it?
http://www.joomultra.com - Premium Joomla Extensions

User avatar
gubagy
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Sun May 17, 2009 12:57 pm
Location: The Netherlands

Re: Joomla file cache javascript duplication bug

Post by gubagy » Sat Mar 16, 2013 1:56 am

The same with Joomla! 2.5.9
Someone workaround ?

Thanks in advance !

Greetz Guby
Learning is not mandatory...
Surviving also not !

User avatar
stutteringp0et
Joomla! Ace
Joomla! Ace
Posts: 1389
Joined: Sat Oct 28, 2006 11:16 pm
Location: Texas
Contact:

Re: Joomla file cache javascript duplication bug

Post by stutteringp0et » Sat Mar 16, 2013 2:16 am

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.
My extensions: http://extensions.joomla.org/profile/pr ... ails/18398
Honk if this signature offends you.

jiggo
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Apr 10, 2013 8:10 am

Re: Joomla file cache javascript duplication bug

Post by jiggo » Wed Apr 10, 2013 8:12 am

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

User avatar
stutteringp0et
Joomla! Ace
Joomla! Ace
Posts: 1389
Joined: Sat Oct 28, 2006 11:16 pm
Location: Texas
Contact:

Re: Joomla file cache javascript duplication bug

Post by stutteringp0et » Wed Apr 10, 2013 12:34 pm

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.
My extensions: http://extensions.joomla.org/profile/pr ... ails/18398
Honk if this signature offends you.

Rezayusefi
I've been banned!
Posts: 24
Joined: Tue Jan 15, 2013 7:05 am

Re: Joomla file cache javascript duplication bug

Post by Rezayusefi » Sun Apr 14, 2013 10:46 am

stutteringp0et how can i cache JS in joomla?

User avatar
stutteringp0et
Joomla! Ace
Joomla! Ace
Posts: 1389
Joined: Sat Oct 28, 2006 11:16 pm
Location: Texas
Contact:

Re: Joomla file cache javascript duplication bug

Post by stutteringp0et » Sun Apr 14, 2013 4:34 pm

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.
My extensions: http://extensions.joomla.org/profile/pr ... ails/18398
Honk if this signature offends you.

User avatar
keh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 188
Joined: Fri Sep 16, 2005 4:55 pm
Location: Oslo
Contact:

Re: Joomla file cache javascript duplication bug

Post by keh » Sun Jun 09, 2013 10:20 am

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...

User avatar
stutteringp0et
Joomla! Ace
Joomla! Ace
Posts: 1389
Joined: Sat Oct 28, 2006 11:16 pm
Location: Texas
Contact:

Re: Joomla file cache javascript duplication bug

Post by stutteringp0et » Sun Jun 09, 2013 3:30 pm

this is related to cache
My extensions: http://extensions.joomla.org/profile/pr ... ails/18398
Honk if this signature offends you.

User avatar
keh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 188
Joined: Fri Sep 16, 2005 4:55 pm
Location: Oslo
Contact:

Re: Joomla file cache javascript duplication bug

Post by keh » Sun Jun 09, 2013 3:54 pm

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.

creativedotit
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Oct 10, 2013 11:09 am

Re: Joomla file cache javascript duplication bug

Post by creativedotit » Thu Oct 10, 2013 12:09 pm

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)


Locked

Return to “General Questions/New to Joomla! 2.5”