We wanted to setup the Google Closure Compiler (https://www.drupal.org/project/closure_compiler) to minify the JavaScript files.
It seemed to be the easiest way to let the Closure Compiler scan through all JavaScript files and minify the missing ones, as soon as AdvAgg created new aggregations.
But the thing is, that there was no hook that was triggered after writing the files to disk.
The last hook triggered is advagg_save_aggregate_alter, right before the writing to disk starts.
The Closure Compiler has a hard processing limit of 200kb per file, larger JS content won't be accepted by the API.
Any larger files are sent to the API using their URL, so the Google server can download and process the JS content remotely.
In order to do that, the files need to be available in the file system, before sending out the request to minify them.
So I introduced a new hook: advagg_save_aggregate_post_alter.
Comment | File | Size | Author |
---|---|---|---|
#15 | advagg-2826075-14-fix-temp-chmod.patch | 4.89 KB | mikeytown2 |
#14 | advagg-2826075-14-fix-temp-chmod.patch | 4.89 KB | mikeytown2 |
#10 | advagg-post_save_hook-2826075-10.patch | 1.97 KB | timur_eatsmarter |
#2 | advagg-post_save_hook-2826075-1.patch | 2.06 KB | timur_eatsmarter |
Comments
Comment #2
timur_eatsmarter CreditAttribution: timur_eatsmarter commentedComment #3
mikeytown2 CreditAttribution: mikeytown2 commentedHave you tried the AdvAgg External Compression module? Has support for Google Closure Compiler via local or remote (via curl).
Comment #4
mikeytown2 CreditAttribution: mikeytown2 commentedComment #8
mikeytown2 CreditAttribution: mikeytown2 commentedComment #9
mikeytown2 CreditAttribution: mikeytown2 commentedPatch doesn't apply and I need to know if the AdvAgg External Compression submodule does what you need it to do.
Comment #10
timur_eatsmarter CreditAttribution: timur_eatsmarter commentedComment #11
timur_eatsmarter CreditAttribution: timur_eatsmarter commentedI'm afraid the External Compression submodule can't supply any JS files to the Online Google Closure Compiler.
I used the example given on the config page (curl -o {%OUT%} -d output_info=compiled_code -d code_url={%IN_URL_ENC%} http://closure-compiler.appspot.com/compile), but nothing seems to happen.
After adding some watchdog messages to advagg_ext_compress_js_compress() and advagg_ext_compress_execute_cmd() I found out, that Google has no access to the temporary JS files (e.g. sites/default/files/advagg_file_qj7Czq.js).
The files are created having the permission -rw------- and thus can't be delivered by Apache.
Comment #12
mikeytown2 CreditAttribution: mikeytown2 commentedOk that shouldn't be too hard to fix. I'll get you a patch later on today
Comment #13
mikeytown2 CreditAttribution: mikeytown2 commentedTesting the patch you submitted
Comment #14
mikeytown2 CreditAttribution: mikeytown2 commentedHere's the fix for temp file permissions and better logging of errors.
Comment #15
mikeytown2 CreditAttribution: mikeytown2 commentedComment #18
mikeytown2 CreditAttribution: mikeytown2 commentedThis patch is in the latest dev now.
Comment #19
timur_eatsmarter CreditAttribution: timur_eatsmarter commentedThanks for the patch.
I tested the External Compression submodule thoroughly, but I was not able to get the Closure Compiler to work.
Worked fine on my local dev environment, but on sandbox nothing happened, not even a single error message.
Since I ran out of time for now, we will stick to the post_save_hook patch for the time being, and will give the External Compression submodule a chance sometime later.
Maybe there is anybody else that can test the combination of External Compression, Command Line and Google Closure Compiler?
Comment #20
mikeytown2 CreditAttribution: mikeytown2 commentedAny word on where this is for you?
Comment #21
mikeytown2 CreditAttribution: mikeytown2 commented