Discovered via bug 36463, while we compress application/javascript, which is how we serve static .js files (though that may well be OS-dependent, coming from /etc/mime.types), we don't compress text/javascript, which is what output_with_http_headers produces when you ask for 'js'. That's actually currently the correct choice, since in May 2022 RFC 9239 obsoleted RFC 4329 which from 2006 to 2022 said that application/javascript was correct. Not many things seem to actually use output_with_http_headers for js (and most of them seem to actually mean json rather than js), but one huge one does: the initial load of svc/cataloguing/framework for the advanced cataloging editor loads an uncompressed 1.9MB of js (json, but because it's loaded through RequireJS, it winds up loaded as js rather than json, and serving it as json would produce an annoying browser warning) which compressed is a lovely 176KB.
Created attachment 164443 [details] [review] Bug 36531: Serve text/javascript compressed, like application/javascript is Koha serves static .js files as application/javascript (if /etc/mime.types says to) and serves them compressed, but output_with_http_headers uses the currently-correct text/javascript mimetype, and Koha doesn't compress that. Test plan: 1. Set the preference EnableAdvancedCatalogingEditor to Enable. 2. Open the browser Web Developer Tools to the Network tab 3. Load Cataloging - Advanced editor 4. Click on the line for the framework?frameworkcode=&callback=define load 5. Note the content-type text/javascript, no Content-Encoding line, and the size of 1.9MB 6. Apply the patches from bug 36463 if they haven't been pushed, then this patch, and reset_all 7. Repeat steps 1-4, and note a Content-Encoding: gzip header and a Transferred size around 160KB
Created attachment 164465 [details] [review] Bug 36531: Serve text/javascript compressed, like application/javascript is Koha serves static .js files as application/javascript (if /etc/mime.types says to) and serves them compressed, but output_with_http_headers uses the currently-correct text/javascript mimetype, and Koha doesn't compress that. Test plan: 1. Set the preference EnableAdvancedCatalogingEditor to Enable. 2. Open the browser Web Developer Tools to the Network tab 3. Load Cataloging - Advanced editor 4. Click on the line for the framework?frameworkcode=&callback=define load 5. Note the content-type text/javascript, no Content-Encoding line, and the size of 1.9MB 6. Apply the patches from bug 36463 if they haven't been pushed, then this patch, and reset_all 7. Repeat steps 1-4, and note a Content-Encoding: gzip header and a Transferred size around 160KB Signed-off-by: David Nind <david@davidnind.com>
Created attachment 164498 [details] [review] Bug 36531: Serve text/javascript compressed, like application/javascript is Koha serves static .js files as application/javascript (if /etc/mime.types says to) and serves them compressed, but output_with_http_headers uses the currently-correct text/javascript mimetype, and Koha doesn't compress that. Test plan: 1. Set the preference EnableAdvancedCatalogingEditor to Enable. 2. Open the browser Web Developer Tools to the Network tab 3. Load Cataloging - Advanced editor 4. Click on the line for the framework?frameworkcode=&callback=define load 5. Note the content-type text/javascript, no Content-Encoding line, and the size of 1.9MB 6. Apply the patches from bug 36463 if they haven't been pushed, then this patch, and reset_all 7. Repeat steps 1-4, and note a Content-Encoding: gzip header and a Transferred size around 160KB Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Pushed for 24.05! Well done everyone, thank you!
Pushed to 23.11.x for 23.11.06
Backported to 23.05.x for upcoming 23.05.12