[RFC|Merged] Template tag to include JS files

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.
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Template tag to include JS files

Post by brunoais »

Hum... I think INCLUDEJS shouldn't place the scripts in the footer by se. It should place the scripts right after jQuery or leave where they are at the moment.
There are scripts that simply do not need jQuery so there is no need to have control when they are included and may just be included where they are.
I was thinking of:
INCLUDEJS -> Includes the js somewhere that, anyway, assures that it is under jQuery
INCLUDEJS_HERE -> Includes the js in that exact place (it's like having the <script> tag right now. This works exclusively as a replacement system to find the .js file)

And there should be a tag where you mark the place where the scripts are meant to be placed. I don't know if there's already but I don't remember reading that.

This should not loose the order the scripts appear in the page (easy to implement, anyway) there are many times where this is crucial.

BTW: Placing many scripts in the bottom is a bad idea (not so bad as placing them in the head without defer) but it's bad, anyway. I already had situations where the page seem loaded and get irritated when I try something that uses js and nothing happens. E.g. I press the delete post button but, as script didn't execute yet, it shows me the delete post page and not the js counterpart. This is a simple example, but with more complex stuff the thing can be annoying.

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Template tag to include JS files

Post by callumacrae »

Please keep your defer rubbish to the defer thread.

If a style author wants to include a script where it is… they can use a script tag
Made by developers, for developers!
My blog

User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Template tag to include JS files

Post by brunoais »

callumacrae wrote:Please keep your defer rubbish to the defer thread.

If a style author wants to include a script where it is… they can use a script tag
What about if "I", template maker, want to use a script tag that comes from one my template's parents?
How do I solve that specific problem? Do I need to know exactly where that file is?

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Template tag to include JS files

Post by callumacrae »

JavaScript should go in the footer, anyway
Made by developers, for developers!
My blog

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Template tag to include JS files

Post by Arty »

brunoais, I think you are missing the point of INCLUDEJS. If someone wants to keep script in specific place, he can use <script> tag. INCLUDEJS's purpose is to add script to footer after jQuery, so script would be included after jQuery and could use jQuery.

User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Template tag to include JS files

Post by brunoais »

Let's see...
It's still not 100% decided if jQuery will be in the footer anyway.
If it wasn't thought, I think this INCLUDEJS system should work with the parent child to allow the parent of the parent, etc... to have the real script that is included in the file.
The objective is to have this job completely simplified. There was already another tag that, IIRC, was discussed and dropped. I'm supposing this is the replacement.
As a thing like that, it should support the 100% sure it'll be under under jQuery (like now) and it should support let it be placed here.
(I'm not going to press the same button again (only mention it) (defer))
We could have a tag that tells: jQuery is here.
Where that tag is placed, the script tag for jQuery is placed all the accumulated script tags are written and a variable is set to true. After that there is no difference between the tag that inserts the script in that place and that inserts after jQuery.
With this:
If you place the marker in the footer, scripts set to appear after jQuery appear only in the footer after jQuery.
If the marker is in the head then all scripts that are in the body appear where they are.

Anyway, this really requires a partial rewrite of editor.js. I already have an idea about that in my proposal for the use of defer. There's a great possibility that there is a better solution. Anyway I will not lose to an opinion to choose worse options than mine without a fight.

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] Template tag to include JS files

Post by hanakin »

it makes sense to put all code used in one unified place. if we want to put the library stuff in a different place then the theme code finei could be ok with

The inclusion of jQuery recieved heavy weight from myself and igorw during the modernization for the theme as current js for the theme is using very bad practices and jQuery provided an easy simple method to eliviate this but unfortunately it requires converting all of these inline event handles of which their are hundreds which point to several different functions of which I myslef am not 100% what are doing as they were horibbly coded(lack of comments or standardization throught). I have been recently working on going through and one by one reworking all of these but it is a long and arguis process

By doing a to complete strip of the JS from the template files so that we are not attaching onclick events to HTML elements via inline but rather caching them and adding events to them in one easy to edit and contoroled location we are seperating the JS from the template to allow theme authors to easily change any aspect of the theme without breaking the JS

having the chached dom elements required for the JS in the footer or in its own file that we include via this method in the footer allows them to easily change the pointer to the dom element they created. It also allows us to essentially wrap all the jQuery with in the jQuery object protecting us for use of all JS. Putting them in the header is quite comfusing as its in the middle of all the HTML where as the footer it is litteraly above 2 html tags body close and html close wmaking it cleaner and easier to work with, exspecially for a novice coder
Donations welcome via Paypal Image

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Template tag to include JS files

Post by callumacrae »

Just had a thought; template/ajax.js should be the last file to be included.
Made by developers, for developers!
My blog

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Template tag to include JS files

Post by Arty »

callumacrae wrote:Just had a thought; template/ajax.js should be the last file to be included.
Not a problem, it can be included in footer in this order:

Include jQuery
Include core.js from assets
<!-- INCLUDEJS ajax.js -->
{SCRIPTS}

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Template tag to include JS files

Post by callumacrae »

Other way round :-P

core.js, then {SCRIPTS}, then ajax.js


EDIT: Ignore that, you're using INCLDEJS. Why are you using INCLUDEJS? XD
Made by developers, for developers!
My blog

Post Reply