Joomla file cache javascript duplication bug
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.
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.
-
- Joomla! Fledgling
- Posts: 3
- Joined: Tue Oct 25, 2011 8:31 am
Joomla file cache javascript duplication bug
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?
<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?
-
- Joomla! Fledgling
- Posts: 3
- Joined: Wed May 30, 2012 6:58 am
Re: Joomla file cache javascript duplication bug
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.
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.
-
- Joomla! Fledgling
- Posts: 3
- Joined: Wed May 30, 2012 6:58 am
Re: Joomla file cache javascript duplication bug
I found out that the problem exists only for the modules that are not cached and only when a user is not logged in.
- rizor
- Joomla! Apprentice
- Posts: 5
- Joined: Thu Feb 11, 2010 8:59 am
- Location: Roma, italy
- Contact:
Re: Joomla file cache javascript duplication bug
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:
2) but they will be duplicated with:
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
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
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.
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.
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(
Code: Select all
$document->addScriptDeclaration()
$document->addStyleDeclaration()
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" ...
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/');
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';}
Using beez20, there is no way I could get duplicate headers after 10 reloads of different pages.
- stutteringp0et
- Joomla! Ace
- Posts: 1389
- Joined: Sat Oct 28, 2006 11:16 pm
- Location: Texas
- Contact:
Re: Joomla file cache javascript duplication bug
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
https://github.com/joomla/joomla-platform/issues/673
My extensions: http://extensions.joomla.org/profile/pr ... ails/18398
Honk if this signature offends you.
Honk if this signature offends you.
-
- Joomla! Apprentice
- Posts: 27
- Joined: Wed Apr 15, 2009 7:22 am
Re: Joomla file cache javascript duplication bug
I still get this problem with joomla 2.5.8.
How to fix it?
How to fix it?
http://www.joomultra.com - Premium Joomla Extensions
- gubagy
- Joomla! Apprentice
- Posts: 34
- Joined: Sun May 17, 2009 12:57 pm
- Location: The Netherlands
Re: Joomla file cache javascript duplication bug
The same with Joomla! 2.5.9
Someone workaround ?
Thanks in advance !
Greetz Guby
Someone workaround ?
Thanks in advance !
Greetz Guby
Learning is not mandatory...
Surviving also not !
Surviving also not !
- stutteringp0et
- Joomla! Ace
- Posts: 1389
- Joined: Sat Oct 28, 2006 11:16 pm
- Location: Texas
- Contact:
Re: Joomla file cache javascript duplication bug
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.
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.
Honk if this signature offends you.
-
- Joomla! Fledgling
- Posts: 2
- Joined: Wed Apr 10, 2013 8:10 am
Re: Joomla file cache javascript duplication bug
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
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
- stutteringp0et
- Joomla! Ace
- Posts: 1389
- Joined: Sat Oct 28, 2006 11:16 pm
- Location: Texas
- Contact:
Re: Joomla file cache javascript duplication bug
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.
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.
Honk if this signature offends you.
-
- I've been banned!
- Posts: 24
- Joined: Tue Jan 15, 2013 7:05 am
Re: Joomla file cache javascript duplication bug
stutteringp0et how can i cache JS in joomla?
- stutteringp0et
- Joomla! Ace
- Posts: 1389
- Joined: Sat Oct 28, 2006 11:16 pm
- Location: Texas
- Contact:
Re: Joomla file cache javascript duplication bug
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.
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.
Honk if this signature offends you.
- keh
- Joomla! Enthusiast
- Posts: 188
- Joined: Fri Sep 16, 2005 4:55 pm
- Location: Oslo
- Contact:
Re: Joomla file cache javascript duplication bug
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...
- stutteringp0et
- Joomla! Ace
- Posts: 1389
- Joined: Sat Oct 28, 2006 11:16 pm
- Location: Texas
- Contact:
Re: Joomla file cache javascript duplication bug
this is related to cache
My extensions: http://extensions.joomla.org/profile/pr ... ails/18398
Honk if this signature offends you.
Honk if this signature offends you.
- keh
- Joomla! Enthusiast
- Posts: 188
- Joined: Fri Sep 16, 2005 4:55 pm
- Location: Oslo
- Contact:
Re: Joomla file cache javascript duplication bug
Yes. I read the headerstutteringp0et wrote:this is related to cache
The joomla file cache javascript duplication bug I had came from copying joomla installs to another location. I tested with to different servers setups.
-
- Joomla! Fledgling
- Posts: 2
- Joined: Thu Oct 10, 2013 11:09 am
Re: Joomla file cache javascript duplication bug
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)
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)