Message from discussion
How do I prevent loading Javascript twice?
Date: Tue, 13 Mar 2012 08:08:10 -0700 (PDT)
From: subtextproductions <alonzo.tur...@subtextproductions.com>
To: joomla-dev-general@googlegroups.com
Message-ID: <18526923.275.1331651290299.JavaMail.geo-discussion-forums@ynes7>
In-Reply-To: <1b6095a1-8c9d-4fc7-b4fa-1f1ba0b2dd03@eb6g2000vbb.googlegroups.com>
References: <c850c7d3-a734-4b1f-a9fe-b5ff35e34ad7@sv8g2000pbc.googlegroups.com>
<7556370.1770.1331400848371.JavaMail.geo-discussion-forums@pbbqt4>
<CAHQ22MSHmoYj-MDqMSpf35XSYKLaGNMH4_1LP4Wet-S2a+zXbw@mail.gmail.com>
<CALVd8hGRtkFae_br_+vkoH7C7Eht6dpq8Zi_y_frD6_DPUbC1Q@mail.gmail.com>
<CAPPbTZUnPEOQ8TRgMZ2Fp8jhHEUbwccn+s8vup6ZHEot1ftbYw@mail.gmail.com> <27272380.2236.1331620938272.JavaMail.geo-discussion-forums@pbcql4>
<1b6095a1-8c9d-4fc7-b4fa-1f1ba0b2dd03@eb6g2000vbb.googlegroups.com>
Subject: Re: How do I prevent loading Javascript twice?
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_273_16986933.1331651290297"
------=_Part_273_16986933.1331651290297
Content-Type: multipart/alternative;
boundary="----=_Part_274_18276658.1331651290297"
------=_Part_274_18276658.1331651290297
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
In Joomla 1.6 and later there is a new system event "onBeforeCompileHead".
I think that this is the right place to double check javascripts. Hopefully
all of the components, plugins, and modules you are using for your site are
loading javascript with the document class as mentioned previously in this
thread. If so, then everything that is going to be added has been added to
the head just before onBeforeCompileHead. Using this event you can loop
through the loaded javascripts and filter out the ones you don't want.
The real difficulty is that not every included script will have its version
somewhere in the name, so it can be very difficult to try and figure out
which of the multiple loading jQuery libraries is the correct one to load.
Even more complicated is that the script declaration is not an array that
you can loop through. Every new script declaration is simply appended to
the end of the existing string.
I think the core team really wants to address this issue, because its a
common problem that I see amongst Joomla sites. People download a bunch of
different extensions and each one loads its own copy of jQuery without
checking to see if it is already loaded. I don't even want to use jQuery, I
want to use either MooTools or Prototype, and I think there should be a way
to replace the entire UI/UX layer in much the same way we can adjust
templates to change the look of the site.
On Tuesday, March 13, 2012 6:11:08 AM UTC-5, piotr_cz wrote:
>
> There could be a way worth investigating (I didn't try it out):
>
> Did you notice, how MooTools are loaded? Library may be referenced in
> different places, but at the end it's loaded only once using JHtml
> class, particularly JHtml::_('behavior.framework');
>
> My idea is to create a system plugin (those are dispatched before any
> other extensions: components, modules or templates), which would add
> new ('behavior.jquery'). You will reference it later in your
> extensions. The registration code would be inspired by
> behavior.framework
>
> Take a look at:
> http://docs.joomla.org/JHtml::addIncludePath/11.1
> http://docs.joomla.org/JHtml::register/11.1
>
>
> http://api.joomla.org/__filesource/fsource_Joomla-Platform_HTML_librariesjoomlahtmlhtmlbehavior.php.html#a38
------=_Part_274_18276658.1331651290297
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
In Joomla 1.6 and later there is a new system event "onBeforeCompileHead". =
I think that this is the right place to double check javascripts. Hopefully=
all of the components, plugins, and modules you are using for your site ar=
e loading javascript with the document class as mentioned previously in thi=
s thread. If so, then everything that is going to be added has been added t=
o the head just before onBeforeCompileHead. Using this event you can loop t=
hrough the loaded javascripts and filter out the ones you don't want.<div><=
br></div><div>The real difficulty is that not every included script will ha=
ve its version somewhere in the name, so it can be very difficult to try an=
d figure out which of the multiple loading jQuery libraries is the correct =
one to load. Even more complicated is that the script declaration is not an=
array that you can loop through. Every new script declaration is simply ap=
pended to the end of the existing string.</div><div><br></div><div>I think =
the core team really wants to address this issue, because its a common prob=
lem that I see amongst Joomla sites. People download a bunch of different e=
xtensions and each one loads its own copy of jQuery without checking to see=
if it is already loaded. I don't even want to use jQuery, I want to use ei=
ther MooTools or Prototype, and I think there should be a way to replace th=
e entire UI/UX layer in much the same way we can adjust templates to change=
the look of the site.<br><br>On Tuesday, March 13, 2012 6:11:08 AM UTC-5, =
piotr_cz wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">There could be =
a way worth investigating (I didn't try it out):
<br>
<br>Did you notice, how MooTools are loaded? Library may be referenced in
<br>different places, but at the end it's loaded only once using JHtml
<br>class, particularly JHtml::_('behavior.framework')<wbr>;
<br>
<br>My idea is to create a system plugin (those are dispatched before any
<br>other extensions: components, modules or templates), which would add
<br>new ('behavior.jquery'). You will reference it later in your
<br>extensions. The registration code would be inspired by
<br>behavior.framework
<br>
<br>Take a look at:
<br><a href=3D"http://docs.joomla.org/JHtml::addIncludePath/11.1" target=3D=
"_blank">http://docs.joomla.org/JHtml::<wbr>addIncludePath/11.1</a>
<br><a href=3D"http://docs.joomla.org/JHtml::register/11.1" target=3D"_blan=
k">http://docs.joomla.org/JHtml::<wbr>register/11.1</a>
<br>
<br><a href=3D"http://api.joomla.org/__filesource/fsource_Joomla-Platform_H=
TML_librariesjoomlahtmlhtmlbehavior.php.html#a38" target=3D"_blank">http://=
api.joomla.org/__<wbr>filesource/fsource_Joomla-<wbr>Platform_HTML_<wbr>lib=
rariesjoomlahtmlhtmlbehavio<wbr>r.php.html#a38</a></blockquote></div>
------=_Part_274_18276658.1331651290297--
------=_Part_273_16986933.1331651290297--