Avoiding multiple jQuery files?

Discussion forum for MOD Writers regarding MOD Development.
User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20792
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Avoiding multiple jQuery files?

Post by RMcGirr83 » Tue Mar 15, 2011 2:45 pm

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?
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 16641
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Avoiding multiple jQuery files?

Post by DavidIQ » Tue Mar 15, 2011 3:07 pm

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
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4616
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Avoiding multiple jQuery files?

Post by VSE » Tue Mar 15, 2011 4:32 pm

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.
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4616
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Avoiding multiple jQuery files?

Post by VSE » Tue May 10, 2011 7:15 pm

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-)
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 24307
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Avoiding multiple jQuery files?

Post by Paul » Sun Jul 03, 2011 12:32 pm

That still will give issues, if your MOD requires a certian jQuery version, while the earlier included version is lower or something :).
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4616
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Avoiding multiple jQuery files?

Post by VSE » Sun Jul 03, 2011 5:57 pm

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-)
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 24307
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Avoiding multiple jQuery files?

Post by Paul » Sun Jul 03, 2011 8:07 pm

For 3.0 that will not happen, as far I can see :). So for that there needs to be a real solution :/
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

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 » Sun Jul 03, 2011 11:59 pm

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

User avatar
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 24307
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Avoiding multiple jQuery files?

Post by Paul » Mon Jul 04, 2011 4:49 am

Dont forgot that remove javascript is not allowed for MODs within the MODDB. Your MOD will be denied if you use remote javascript.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

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 » Mon Jul 04, 2011 8:08 am

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™ » Sat Oct 17, 2015 5:08 pm

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”

Who is online

Users browsing this forum: oBot and 11 guests