[RFC] Make the use of defer mandatory

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Post Reply
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC]Make the use of defer mandatory

Post by callumacrae »

Arty wrote:
callumacrae wrote:This means that we're going to have to rewrite any code that changes anything DOM-wise on page load to use document.ready.
Nothing changes for that code. onload event isn't going anywhere.
It would make sense to rewrite it, but its not required.
callumacrae wrote:Why not use defer, but keep it in the footer? (like html5bp does)
Using defer in footer makes whole idea of using defer void.
Yeah, it would need changing to support browsers that don't support defer.

Not really. It performs exactly the same in modern browsers, and doesn't slow down the page on older browsers.

I'm assuming that HTML5BP uses defer in the footer for very good reason. Paul Irish is a very good developer, and knows what he is doing.
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]Make the use of defer mandatory

Post by Arty »

There is a good reason for him using defer in footer: load script after DOM is loaded if browser supports defer, load script at the end of page if browser doesn't support it.

But that reason doesn't apply to forums because layout is not the same on every page. There are mods and page specific scripts. Adding those scripts should not require editing footer and that's where defer comes in handy.

Major argument for including jquery in footer was page loading speed. Major argument for including it in header was allowing to use jquery in scripts before footer. Defer solves that conflict, allowing both.

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

Re: [RFC]Make the use of defer mandatory

Post by callumacrae »

defer is HTML4 and has been supported in Internet Explorer since IE4. Why did noone tell me this?! XD

I withdraw most of my objections - but I still think the scripts should remain in the footer with defer. This is what the Yahoo! Exceptional Performance team and and HTML5 Boilerplate recommend.
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]Make the use of defer mandatory

Post by Arty »

Their recommendations don't account for complexity of forum styling ;)

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

Re: [RFC]Make the use of defer mandatory

Post by callumacrae »

I'm reading a book on the subject right now, written by a few members of the Yahoo! Exceptional Performance team. It covers everything >_<
Made by developers, for developers!
My blog

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

Re: [RFC]Make the use of defer mandatory

Post by hanakin »

Arty wrote:Their recommendations don't account for complexity of forum styling ;)
I would argue that the complexity is mishandled and that the pafge specific js should be added to the footer.

first off all we need to seperate all js out of the tempate into its own folder possibly within the template folder possibly within the theme folder posibly in its own folder. The server should then combine and compress all the js using its own template file similar too the way http://net.tutsplus.com/articles/news/i ... version-2/ does then this file would be what is include in the footer along with the jquery this would provide the best method as your scripts would be in one file requireing 1 defer/1 server request other than jquery and serving the smallest file possible to handle all the interactions.

seeing as how the current script files each total 12k once properly recoded for efficiency and externalizing all the js from the template this should be far smaller as a combined fil to begin with, add to that the minification and possibly even gziping and the server would only have to fetch a file under approximately 5k if that.

Proposal:
  1. create new folder containing all js files
  2. within new directory create new template file js.html or something along those lines
  3. within said file put all the script includes other than jquery
  4. parse this template on the backend to combine, minify and optionaly compress all of the include script files into js-combined.js
  5. in overall-footer.html after the jquery includes, include the combine script
this optimally will provide mod authors to easily append thier own scripts in a seperate file to serve into the parsing
Donations welcome via Paypal Image

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

Re: [RFC]Make the use of defer mandatory

Post by Oleg »

How about handling javascript the right way, by which I mean:

1. Separate the notion of requiring javascript from the act of printing script tags in markup, by adding a layer of indirection. The code that requires some javascript file should store that fact somewhere for later use. In the templates read the list of needed javascript files and output them.

2. Subsequently, implement both loading javascripts in the header via defer and in the footer. Use the former version for everything but opera and the latter version for opera.

Asset combining follows fairly naturally, should we need it. It is also rather trivial to output js inline instead of referencing js files for development purposes.

I'm thinking #1 could be implemented via a new template tag.

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

Re: [RFC]Make the use of defer mandatory

Post by hanakin »

Oleg wrote:How about handling javascript the right way, by which I mean:

1. Separate the notion of requiring javascript from the act of printing script tags in markup, by adding a layer of indirection. The code that requires some javascript file should store that fact somewhere for later use. In the templates read the list of needed javascript files and output them.

2. Subsequently, implement both loading javascripts in the header via defer and in the footer. Use the former version for everything but opera and the latter version for opera.

Asset combining follows fairly naturally, should we need it. It is also rather trivial to output js inline instead of referencing js files for development purposes.

I'm thinking #1 could be implemented via a new template tag.
not sure i really understand your logic to clarify
#1 would work perfectly with my proposal,
#2 makes no real sense too me why do we need both , still makes no sense to me to include in header if the JS is handled the right way.
#3 is where i get confused with what you are trying to say. Are you saying that it is trivial to remnove/externalize the JS from the template files or give them their own director/template file?

I have been doing front-end development for going on 11 yrs now and every project weather it be stand alone site, cms generated, or application theme and have always followed a strict seperation of effort for the file structure

JS, CSS, & images have always had their own file this makes working with, updating, replacing the theme extremely easy as you go exactly where you ned to to edit specifically what you want. I have never really understood PHPBB's idea of a file structure for their themes it has always been convluted and confusing from a developer mind set let alone the average user.

calling the css folder theme is one as well as including the image folder with in it but why do we not encapsulate the js files as they are seperate from the template it self after all JS is an enhancement not a part of a template, further more if you really want to get nitpicky the en folder should really be put within the images directory.
Donations welcome via Paypal Image

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

Re: [RFC]Make the use of defer mandatory

Post by Arty »

Oleg wrote:How about handling javascript the right way, by which I mean:

1. Separate the notion of requiring javascript from the act of printing script tags in markup, by adding a layer of indirection. The code that requires some javascript file should store that fact somewhere for later use. In the templates read the list of needed javascript files and output them.

2. Subsequently, implement both loading javascripts in the header via defer and in the footer. Use the former version for everything but opera and the latter version for opera.

Asset combining follows fairly naturally, should we need it. It is also rather trivial to output js inline instead of referencing js files for development purposes.

I'm thinking #1 could be implemented via a new template tag.
1. That would require rewriting a lot of code and adding new template tag. It is a good idea for 4.0, but I'm not sure if this is a good idea for 3.x

2. Why complicate things? If browser doesn't support defer, it can load script in header. It is not the end of the world. Loading time difference is tiny, users can barely notice it.

igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] Make the use of defer mandatory

Post by igorw »

I agree with Arty that implementing both is probably not worth it. Just using defer is very easy to do and works in a wide range of browsers. Only opera does not support it. And while the slowdown for those who don't support it is not so nice, it's not that much of a problem either.

Post Reply