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.