Problem/Motivation
Our current logic for building CSS and Javascript aggregates suffers from a number of issues:
1. When files don't exist on the file system, they're generated inline, this means that the HTML for any page containing the same aggregate can't complete until one of the pages requested has built it.
2. Additionally it requires state gets and sets to keep track of file names. This was more of an issue in Drupal 7 with variables, but still not ideal.
3. Generating aggregates, especially for CSS, can be quite expensive, so this adds significantly to the time taken from a cache clear to 'first full page request served'.
4. Because it's expensive already, it makes it difficult to add on-the-fly js minification and similar, since that would further degrade cold cache performance.
Proposed resolution
Instead of generating files inline, generate a filename with enough information for the following:
1. The group the filename represents
2. A hash of the css/js asset definitions from the libraries to ensure the code base matches and that updated library definitions result in new aggregate filenames.
These are enough to guarantee unique hashes for the files themselves.
Then add the following in the query string so that the PHP request has sufficient context to generate that same hash:
1. The libraries for the request that were used to generate the groups
2. The theme for the request.
Remaining tasks
I've implemented this for CSS, which is the harder one to do.
JS has not been touched yet.
CSS libraries do not lend themselves to a small minimal representative subset, which means we need to figure out if this is going to result in a GET request that's too long (the libraries are only required by the PHP callback with this implementation, so this does not break file sizes).
User interface changes
None.
API changes
Quite big changes to the optimizer/grouper class logic and potentially an extra interface needed.
Data model changes
Will drop two state entries.