1
nmshah
jquery being loaded multiple times
  • 2010/12/25 4:14

  • nmshah

  • Just can't stay away

  • Posts: 556

  • Since: 2007/7/2 8


I am currently working on a new theme for my website. The website uses mymenus and publisher. Looking at the source of one of the pages in the head section I see that jquery is being loaded three times, one each by the theme, mymenus and publisher. Also there are multiple .js files being loaded.

Is there a way that I can prevent the multiple loading of jquery. What are the changes that I need to make in mymenus and publisher module to stop loading the jquery so that the modules can use the jquery loaded by the theme?

2
voltan
Re: jquery being loaded multiple times
  • 2010/12/25 10:21

  • voltan

  • Theme Designer

  • Posts: 724

  • Since: 2006/12/5


Add jquery like this in your theme heder :

<{php}>
/** add JQuery and JQuery UI */
    
global $xoTheme
        
$xoTheme->addScript("browse.php?Frameworks/jquery/jquery.js");
        
$this->assign('xoops_module_header'$xoTheme->renderMetas(nulltrue)); 
<{/
php}>


looking to suico theme . I have this problem too and I found just this way .

in extgallrey I add a option for enables/disables jQuery . perhaps we need a option like this for all part of user side

3
mariane
Re: jquery being loaded multiple times
  • 2010/12/25 12:24

  • mariane

  • Theme Designer

  • Posts: 649

  • Since: 2008/1/11


Voltan I think it's an error in mymenus, me too I have the same thing
the road of success is always under construction

4
voltan
Re: jquery being loaded multiple times
  • 2010/12/26 9:06

  • voltan

  • Theme Designer

  • Posts: 724

  • Since: 2006/12/5


check mymenus whit default theme or theme whit out jQuery .

in my menu jQuery add whti this cood and in php file :
$xoTheme->addScript("browse.php?Frameworks/jquery/jquery.js");

and in theme jQuery added whit
<script type="text/javascript" src="<{xoAppUrl browse.php?Frameworks/jquery/jquery.js}>">script>


and in page source you have 2 jQuery and some of the code's between jQuery1 and jQuery2 do not work

5
nmshah
Re: jquery being loaded multiple times
  • 2010/12/26 11:29

  • nmshah

  • Just can't stay away

  • Posts: 556

  • Since: 2007/7/2 8


Thanks Voltan & Marine for helping and confirming

What changes should i make in mymenu codes to prevent it from loading the jquery? I will like to simply remove the line/code that loads the jquery.

I am using superfish skin

6
redheadedrod
Re: jquery being loaded multiple times

It is bad programming practice to load something like jquery without first checking if it is already loaded. You should add PHP code prior to loading jquery to make sure if it is already loaded or not. Only load if it is necessary.

I have yet to mess with jquery myself but this is a good programming practice for any program like this.

If you can ask for the version of jquery that is loaded that is the easiest way to determine if it is loaded or not.

I am blindly responding to this as I have no current experience with jquery however this would be similar to using "require once" which only loads a PHP include file if it hasn't been loaded yet.

Rodney
Attending College working towards Bachelors in Software Engineering and Network Security.

7
voltan
Re: jquery being loaded multiple times
  • 2010/12/26 17:35

  • voltan

  • Theme Designer

  • Posts: 724

  • Since: 2006/12/5


in your theme jq loaded like this:
<script type="text/javascript" src="<{xoAppUrl browse.php?Frameworks/jquery/jquery.js}>">script>


remove it and add thsi code in your theme:
<{php}>
/** add JQuery and JQuery UI */
    
global $xoTheme
        
$xoTheme->addScript("browse.php?Frameworks/jquery/jquery.js");
        
$this->assign('xoops_module_header'$xoTheme->renderMetas(nulltrue)); 
<{/
php}>

8
ianez
Re: jquery being loaded multiple times
  • 2011/4/19 8:06

  • ianez

  • Not too shy to talk

  • Posts: 188

  • Since: 2006/1/26


the code works but I've a problem with mymenu module...
the code for the jscript menu in the module's header is loaded before the jquery call made by theme..
this creating an error in page loading..

I think it's a 'bug' related to how the skins load jscript code (which is not via the addScript method,
any idea on how can I solve this?

Ian

9
voltan
Re: jquery being loaded multiple times
  • 2011/4/19 13:15

  • voltan

  • Theme Designer

  • Posts: 724

  • Since: 2006/12/5


At modules/mymenus/skins/YOUR_SELECT_SKIN/skin_version.php you can find js files and edit this

10
ianez
Re: jquery being loaded multiple times
  • 2011/4/19 14:23

  • ianez

  • Not too shy to talk

  • Posts: 188

  • Since: 2006/1/26


hi Voltan,
the problem is exactly that the code of mymenu skins call a jquery instance improperly inserting a link to a js folder in the module not using the addScript method..
so when I use a mymenu block with jquery and I open a fmcontent page with uses lightbox the result is this

<script src="http://localhost/xoops250/include/xoops.js" type="text/javascript">script>

<
script type="text/javascript" src="http://localhost/xoops250/class/textsanitizer/image/image.js">script>
<
script src="http://localhost/xoops250/modules/mymenus/skins/superfish/../../js/jquery-1.3.2.min.js" type="text/javascript">script>
<
script src="http://localhost/xoops250/modules/mymenus/skins/superfish/../../js/hoverIntent.js" type="text/javascript">script>
<
script src="http://localhost/xoops250/modules/mymenus/skins/superfish/../../js/superfish.js" type="text/javascript">script>
<
script src="http://localhost/xoops250/browse.php?Frameworks/jquery/jquery.js" type="text/javascript">script>
<
script src="http://localhost/xoops250/browse.php?Frameworks/jquery/plugins/jquery.lightbox.js" type="text/javascript">script>
<
script src="http://localhost/xoops250/browse.php?Frameworks/jquery/plugins/jquery.ui.js" type="text/javascript">script>


as you may see the jquery instance of the skin breaks the following.. (lightbox is not working in this case..).. how can I call jscriptin mymenuskin using the right addScript method?

Ian

Login

Who's Online

418 user(s) are online (295 user(s) are browsing Support Forums)


Members: 0


Guests: 418


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits