[RFC] script.php

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.
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

[RFC] script.php

Post by callumacrae »

There hasn't really been any discussion about serving scripts (and language in scripts) yet, but this seemed to be the most popular idea.


I propose that there be a JavaScript equivalent of style.php, where it takes all the JavaScript files (except jQuery), parses (for language etc), concatenates and possibly minifies them, before sending them off to the client.

This would have many advantages:
  • It would either reduce the amount of HTTP requests or reduce the need for mod authors to add every javascript snippet to a huge file (which would result in conflicts as everyone would be referring to the same piece of code in their MODX)
  • It would make it far easier to use language in JavaScript (I've been using inline language in the AJAX stuff until something is done) and would remove the need for a language class to be written.
  • It would make it easier to control cache-control.
  • Minifying it would reduce bandwidth used and download time
  • It would force mod authors to include their script in the footer

How mod authors should tell script.php to include their script

I think that there should be something similar, again, to style.php - using @import. This would have the disadvantage of possible conflicts during installation / uninstallation, but is better than the alternative - if there is a <!-- USE file.js --> like I previously suggested, then the script.php output would be different for each file as mod authors included stuff on some pages and not others. This would be very bad, as it would make it impossible to cache the script. All the required Javascript should be served every single time, even if it won't be used on that page.

Another alternative would be to have a list of files to include in the database, as this would remove the possibility of conflicts.

I would suggest against automatically including all files found in a certain directory / set of directories.
Made by developers, for developers!
My blog
igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] script.php

Post by igorw »

(I have a few ideas here and will comment in full later)

You could also define a set of 'containers' such as 'common', 'viewtopic', 'viewforum', which are then compiled down to common.js, viewtopic.js, viewforum.js. These are defined declaratively, so that they can be pre-compiled to static files. Extensions can then add scripts to those containers.
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1868
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: [RFC] script.php

Post by DavidIQ »

callumacrae wrote:[*]It would make it far easier to use language in JavaScript (I've been using inline language in the AJAX stuff until something is done) and would remove the need for a language class to be written.
I'm not sure about that. How would you handle different languages? You couldn't have the same JS file "served" for all users on a multi-language board and if you're always building it you would negate the caching of it wouldn't you?
Image
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] script.php

Post by callumacrae »

DavidIQ wrote:
callumacrae wrote:[*]It would make it far easier to use language in JavaScript (I've been using inline language in the AJAX stuff until something is done) and would remove the need for a language class to be written.
I'm not sure about that. How would you handle different languages? You couldn't have the same JS file "served" for all users on a multi-language board and if you're always building it you would negate the caching of it wouldn't you?
Good point, I hadn't thought of that. Dunno how it would be resolved, either.
Made by developers, for developers!
My blog
Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] script.php

Post by Oleg »

Please make it possible to build combined js files during deployment. This means, usually, providing a function that can be called to do the work which performs no interactive actions (input or output).
igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] script.php

Post by igorw »

As long as the definition of the files to be combined is declarative it is possible to compile them statically. But I agree that language should not be compiled in.
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] script.php

Post by callumacrae »

Okay.

This post is about 3.1: can a js directory be introduced into the style directories? Eg:

/styles/prosilver/js/stuff.js

Currently style specific javascript is being stuck into the templates directory, which really doesn't work. The directory could be called "scripts" or "js", but scripts could get confused for PHP. It couldn't really be "assets" because the entire style is assets.
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] script.php

Post by Arty »

callumacrae wrote:This post is about 3.1: can a js directory be introduced into the style directories? Eg:

/styles/prosilver/js/stuff.js

Currently style specific javascript is being stuck into the templates directory, which really doesn't work. The directory could be called "scripts" or "js", but scripts could get confused for PHP. It couldn't really be "assets" because the entire style is assets.
That's a very good idea!
Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] script.php

Post by Oleg »

I would say the same directory name should be used for javascripts globally and in each style - therefore assets/javascript given current global naming.
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] script.php

Post by callumacrae »

What else will go in the assets directory? By the definition of assets according to the coding guidelines, the only other things that could go in there are images and css, both of which are somewhere else, and something like flash which I don't think any style authors use anyway. There is no point in a directory which will only ever have on thing in it.
Made by developers, for developers!
My blog
Post Reply