jQuery (and other javascript) usage in mods

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
doktornotor
Registered User
Posts: 608
Joined: Fri Sep 09, 2011 7:41 am

jQuery (and other javascript) usage in mods

Post by doktornotor »

Guys, I would have a couple of suggestions:

1/ Centralize the placement of the javascript stuff. Like, scripts/, js/ or whatever in root. Having the scripts scattered in various hidden subdirs helps noone.

2/ Specifically for jQuery - please, do NOT try to load it unconditionally. Instead, I have been using this for a while and it works great:

Code: Select all


<script type="text/javascript">
// <![CDATA[
if (window.jQuery === undefined) {
    document.write(unescape('%3Cscript src="{ROOT_PATH}script/jquery-latest.min.js" type="text/javascript"%3E%3C/script%3E'));
}
// ]]>
</script>
Remember that your MOD is not the only in the world and trying to load multiple instances and/or versions of jQuery breaks everything. People flood support forums with issues caused by this.

3/ Do NOT hardcode the jQuery version. Using jquery-latest.min.js in template files makes updating jQuery as simple as overwriting one file with latest jQuery version. Yeah, just one if you manage to centralize the scripts location.

Do NOT rename jQuery to something cryptic for whatever whacky reason. Guess what, e.g. this Wait At Registration mod bundles jQuery 1.3.2 - renamed as countdown.js and installed once per style. OMG, why? And guess what, works perfectly with 1.7.1 :roll:

Besides the conflicts, you are causing possibly vulnerable versions of stuff getting totally unnoticed.

And - as a related side note, I do not find the current policy that does not allow using CDNs for this highly counter-productive. Given the authors inactivity and the validation queue delays, it is impossible to keep up the pace with upstream development. Updating jQuery core generally does not cause any issues, mods that hardcode jQuery 1.4.x or whatever work perfectly fine with 1.7.1).
Support requests via PM go straight to /dev/null!
User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21289
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: jQuery (and other javascript) usage in mods

Post by RMcGirr83 »

FWIW, 3.1 is going to have jQuery in the phpBB core code.
Appreciate the extensions/mods/support then buy me a beer Image
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 | My extensions are updated regularly on github
All requests for support via PM will be ignored
User avatar
doktornotor
Registered User
Posts: 608
Joined: Fri Sep 09, 2011 7:41 am

Re: jQuery (and other javascript) usage in mods

Post by doktornotor »

RMcGirr83 wrote:FWIW, 3.1 is going to have jQuery in the phpBB core code.
Lets up it comes soon... :lol:
Support requests via PM go straight to /dev/null!
Locked

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