One of the performance issues with the CMS is that it has to pre-load
every JS file that you might need to one day news. This also creates
a coupling problem, because CMSMain needs to know about the JS
requirements of every page type in existence.
A solution to this problem is on-demand javascript (and CSS). That
is, Ajax responses should be able to determine when additional
JavaScript files are needed and load them without reloading the page.
For the purposes of this thread, I'm going to ignore CSS, but the
solutions can easily be applied to JS as CSS.
== Proposal one ==
1) Ajax requests would be made as normal
2) Requirement::javascript() calls get made on the server
3) The Ajax response has a number of X-Include-JS headers attached to
it:
X-Include-JS: sapphire/javascript/TableListField.js
X-Include-JS sapphire/javascript/ComplexTableField.js
4) We create a jQuery plugin that traps all ajax requests and checks
for X-Include-JS headers, and if they exist, includes those javascript
files that aren't already included.
5) The success handlers are called once any necessary scripts have
been loaded.
== Proposal two ==
1) Ajax requests would have a number of X-JavaScript-Loaded attached
to them
2) Requirement::javascript() calls get made on the server
3) The Ajax response has a number of X-Include-JS headers attached to
it. X-JavaScript-Loaded would be used to filter out any includes that
have already been included
4) and 5) are the same as above
At this stage I think that we should go with Proposal one, because
it's simpler, but I would like to hear ideas on this.
This jQuery plugin looks like a good one to use:
http://plugins.jquery.com/files/issues/jquery.ondemand.js_.txt
* It generates <script> tags rather than using ajax, which are cached
on more browsers
* It can include CSS and JS
* It will queue up requests and you can attach finished-loading
handlers to each of them