Avoiding multiple jQuery files?

Discussion forum for MOD Writers regarding MOD Development.
User avatar
RMcGirr83
Former Team Member
Posts: 22011
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Avoiding multiple jQuery files?

Post by RMcGirr83 »

jquery_min.js != jquery_1.4.4.js

Because I know mods that have packaged them like that which is why I am asking and what is to stop a user from inserting the library more than once within, say, overall_header?
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18282
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Avoiding multiple jQuery files?

Post by DavidIQ »

There wouldn't be any way to stop a user from doing that and this certainly wouldn't stop them from doing it. Please reread my note:
DavidIQ wrote:The JavaScript files would be organized and you would be able to tell which libraries are already present and not upload the same ones again into some other folder specified by the MOD. Of course this might be a moot point with the hooks present but nonetheless a good suggestion.
The whole point of having the directory is to have one single place for them and not all over the place and for every single style as it is now. The only way that multiple JavaScript file inclusion will be avoided is through a combination of hooks (which don't exist at the moment) and a change in our policies with regard to the adding of these to overall_header.html. This will not be fixable in the 3.0.x line I'm afraid.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5859
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: Avoiding multiple jQuery files?

Post by MattF »

The ultimate goal is just to make the user realize they already have jQuery in use by a MOD, so they can take whatever actions needed to avoid jQuery conflicts.

Case in point:
I just wrote a simple jQuery MOD to show password strength. It worked great on my test boards. But when I installed it on a real board, it broke because there was a captcha plug-in MOD in use that also had jQuery... Oops! Solution was to remove the jQuery inclusion in the captcha plug-in MOD.

There are enough jQuery MODs out there now in both the CDB and Mods in Dev forums to be concerned about this, particularly if you are authoring a MOD that uses jQuery too ;)

Until this 3.1 hooked version eventually arrives, we could at least use some kind of coding guideline/standardization for dealing with these js libraries so MOD authors and users can minimize or even prevent potential conflicts.

ie) A js_libraries folder to keep all these scripts, and lots of warnings when using them in the MODX file and even detection by AutoMOD to signal the user they will be installing jQuery and need to look for potential conflicts from other MODS.

ie) Require any MOD using jQuery put the word jQuery in the MOD's name (should apply to all js libraries).

ie) Or make jQuery (and other libraries) a part of the phpBB installation. And require MOD authors to reference the library that came with phpBB in their MODs if they want to use it. Or even better have a config parameter that a MOD authour just needs to make sure is turned ON and phpBB will automatically include the library in the HEAD tag for you! These libraries can be updated along with the typical phpBB maintenance releases.
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5859
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: Avoiding multiple jQuery files?

Post by MattF »

FWIW, I finally came across this method:

Code: Select all

<script type="text/javascript">
    // <![CDATA[
    !window.jQuery && document.write('<script type="text\/javascript" src="jquery-1.6.min.js"><\/script>');
    // ]]>
</script>
What it seems to do is if jQuery is not already present, then it is dynamically added. The CDATA wrappers make it pass XHTML validation.

If using the above code as the method for including jquery, instead of the default method were adopted by all MOD authors, then I think it could solve this issue, such that only 1 - the first encountered - link to the jQuery library will be loaded. Any other links from other MODs will be ignored. Thus, no more conflicts. 8-)
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28616
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Avoiding multiple jQuery files?

Post by Paul »

That still will give issues, if your MOD requires a certian jQuery version, while the earlier included version is lower or something :).
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5859
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: Avoiding multiple jQuery files?

Post by MattF »

Paul wrote:That still will give issues, if your MOD requires a certian jQuery version, while the earlier included version is lower or something :).
Therein lies the reason why jQuery MUST be included with phpBB... There needs to be a standardized implementation of it so that MOD authors can take advantage of its features without having to worry about versioning and inclusion issues. Let phpBB dictate where it is included and what versions will be used.

In the meantime, end-users will have to figure that out themselves, and determine where they must "MOD" their MODs so that the best version of jQuery for their needs is the version that gets included. :mrgreen:

I think we could take a hint from the HTML5 boilerplate and include jQuery at the footer, followed by a single global "scripts.js" file and a second "plugins.js" file... phpBB core code goes in the scripts.js and new MOD authored code goes in plugins.js. Then, after the first page load, they'll be cached and Bob is your uncle 8-)
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28616
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Avoiding multiple jQuery files?

Post by Paul »

For 3.0 that will not happen, as far I can see :). So for that there needs to be a real solution :/
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Avoiding multiple jQuery files?

Post by 4_seven »

this works for me up to 99,5%:

Code: Select all

<script type="text/javascript">
// <![CDATA[ 
!window.jQuery && document.write('<script type="text\/javascript" src="http:\/\/code.jquery.com\/jquery-latest.min.js"><\/script>');
// ]]> 
</script>
again, thx for this code..
Current Mods | Mod Base | php(BB) programming | No help via PM
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28616
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Avoiding multiple jQuery files?

Post by Paul »

Dont forgot that remove javascript is not allowed for MODs within the MODDB. Your MOD will be denied if you use remote javascript.
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Avoiding multiple jQuery files?

Post by 4_seven »

of course and indeed i know this. but until a mod is not in there, it's the best way.
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
ALX™
Registered User
Posts: 224
Joined: Thu Jun 26, 2014 4:47 pm

Re: Avoiding multiple jQuery files?

Post by ALX™ »

VSE wrote:FWIW, I finally came across this method:

Code: Select all

<script type="text/javascript">
    // <![CDATA[
    !window.jQuery && document.write('<script type="text\/javascript" src="jquery-1.6.min.js"><\/script>');
    // ]]>
</script>
What it seems to do is if jQuery is not already present, then it is dynamically added. The CDATA wrappers make it pass XHTML validation.

If using the above code as the method for including jquery, instead of the default method were adopted by all MOD authors, then I think it could solve this issue, such that only 1 - the first encountered - link to the jQuery library will be loaded. Any other links from other MODs will be ignored. Thus, no more conflicts. 8-)
Good afternoon from Greece!

I had problem me too with mchat (smiley and bbcode buttons) and status mod 1.0.5.
When I put the code of script with jquery 1.3.2.js has conflict with mchat buttons in portal board3 module.
The status mod it works, but the buttons of mchat... not.
When I remove the script code 1.3.2.js from overall_header, mchat buttons it works fine.
I try above code and now all it works OK, but at the upper left corner, I see the

Code: Select all

// ]]>
of code. Why?

EDIT

Ι remove the

Code: Select all

// ]]>


from the end of code and left only the

Code: Select all

</script>


Now all continue to works fine, but the

Code: Select all

// ]]>


disappear from page :D

Weird? :geek:
Forgive me for my bad english :oops:
Locked

Return to “[3.0.x] MOD Writers Discussion”