[RFC|Merged] Include and use jQuery (originally for 3.2)

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
Post Reply
User avatar
MattF
Extension Customisations
Extension Customisations
Posts: 675
Joined: Mon Mar 08, 2010 9:18 am

Re: [RFC|Accepted] Include and use jQuery

Post by MattF »

FWIW, I came across a CDN fallback to local version method, that works...

Code: Select all

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript">
    // <![CDATA[
        !window.jQuery && document.write('<script type="text\/javascript" src="jquery-1.4.3.min.js"><\/script>');
    // ]]>
    </script>
The CDATA wrapper is so this will pass XHTML strict validation.

THis could also be a useful technique for MOD authors to use in the existing jQuery-based MODs out there, to prevent a conflict of multiple inclusions of the jQuery library

So a MOD author could include jquery like this to avoid potential conflicts:

Code: Select all

    <script type="text/javascript">
    // <![CDATA[
        !window.jQuery && document.write('<script type="text\/javascript" src="jquery-1.4.3.min.js"><\/script>');
    // ]]>
    </script>
Bring it on Rich!!! :lol:
Has an irascible disposition.

User avatar
RMcGirr83
Registered User
Posts: 360
Joined: Fri Mar 09, 2007 1:51 am
Contact:

Re: [RFC|Accepted] Include and use jQuery

Post by RMcGirr83 »

Code: Select all

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
Which is fine IF that was allowed within modifications submitted for validation which it isn't. :P

Externally hosted js files are not allowed, no matter which js file it may be (yes, this includes jQuery).
Do not hire Christian Bullock he won't finish the job and will keep your money

User avatar
MattF
Extension Customisations
Extension Customisations
Posts: 675
Joined: Mon Mar 08, 2010 9:18 am

Re: [RFC|Accepted] Include and use jQuery

Post by MattF »

RMcGirr83 wrote:

Code: Select all

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
Which is fine IF that was allowed within modifications submitted for validation which it isn't. :P

Externally hosted js files are not allowed, no matter which js file it may be (yes, this includes jQuery).
I think you misunderstood my post ;)

The first block of code was an example in response to the posts about having a fallback to a CDN. I just posted that as an example of how that could be done - if phpBB were to implement a CDN option, which it seems like the developers don't want to do, which is fine with me by now.

But the second block of code I posted is what I would recommend to any MOD author using jQuery look into using in their own MODs. That has nothing to do with externally hosted CDN scripts. That is merely a way to test for jQuery and include it if its not found, or not include it if it's already present - a perfect solution for preventing multiple inclusions of jQuery.

See this post: http://www.phpbb.com/community/viewtopi ... #p12995210
Has an irascible disposition.

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC|Accepted] Include and use jQuery

Post by Oleg »

VSE+ wrote:FWIW, I came across a CDN fallback to local version method, that works...

Code: Select all

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript">
    // <![CDATA[
        !window.jQuery && document.write('<script type="text\/javascript" src="jquery-1.4.3.min.js"><\/script>');
    // ]]>
    </script>
This reminded me that we should put javascript at the bottom of pages. Hopefully both jquery itself and all of our code.

http://developer.yahoo.com/performance/ ... #js_bottom

As far as practical utility of the quoted fragment is concerned, I run ad blocking locally and my firefox renders itself useless when it is waiting for a connection or a reply from remote server and javascript is involved. In other words the above fragment on my computer, assuming ajax.googleapis.com was dropping all traffic sent to it, would hang page loading forever.

---

I have been staying out of the CDN debate until now but I do offer the following considerations:

1. We must include jquery locally. This is needed to support disconnected (from the internet) operation.

2. Because of #1 the decision is between having a local copy only or having local copy + CDN. Since the local copy is already essentially implemented, whether CDN will be an option or not depends on someone implementing it. In my opinion having CDN support is not a requirement for merging jquery into develop.

How to actually implement CDN seems to be tricky. I am not a big fan of telling admins to edit the code if they want a CDN. We are trying to move away from modifying core code and this in a step in the opposite direction. Perhaps we can simply provide a config variable (hidden or visible) where an admin can put the full path to where they want to get jquery from. This will let admin specify whichever version they want and whichever CDN they want, freeing us from having to maintain a list of CDNs as well as worrying about those CDNs not carrying versions that we use.

User avatar
hanakin
Front-End Dev Team Lead
Front-End Dev Team Lead
Posts: 968
Joined: Sat Dec 25, 2010 9:02 pm
Contact:

Re: [RFC|Accepted] Include and use jQuery

Post by hanakin »

nn- wrote: This reminded me that we should put javascript at the bottom of pages. Hopefully both jquery itself and all of our code.

http://developer.yahoo.com/performance/ ... #js_bottom
totally agree and planned on it for the overhaul, however its not that easy until we convert to jquery and completely consolidate or remove all of the js from the theme since all code must fall after the inclusion of jquery, nothing can be contained in the theme which is one of the main reasons I was pushing to seperate the JS from the theme in the first place. You also run into the issue that a dynamic method to include certain scripts or functions for certain pages only might be devised since lot of the js funtionality is not required but for a few pages, but one can also argue that if we minify and serve it in one file it would be cached.

Also not sure if this would work well with noscript tags have not tested it, but I believe it only displays is JS is turned off by the browser so should be ok
Donations welcome via Paypal Image

Post Reply