Bug 36531

Summary: Koha should serve text/javascript compressed, like application/javascript is
Product: Koha Reporter: Phil Ringnalda <phil>
Component: Architecture, internals, and plumbingAssignee: Phil Ringnalda <phil>
Status: Pushed to oldstable --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: fridolin.somers, lucas
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35799
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00,22.11.06,23.05.12
Bug Depends on: 36463    
Bug Blocks:    
Attachments: Bug 36531: Serve text/javascript compressed, like application/javascript is
Bug 36531: Serve text/javascript compressed, like application/javascript is
Bug 36531: Serve text/javascript compressed, like application/javascript is

Description Phil Ringnalda 2024-04-05 02:42:25 UTC
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.
Comment 1 Phil Ringnalda 2024-04-05 02:53:21 UTC
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
Comment 2 David Nind 2024-04-05 10:32:20 UTC
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>
Comment 3 Nick Clemens (kidclamp) 2024-04-08 11:55:01 UTC
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>
Comment 4 Katrin Fischer 2024-04-08 13:42:58 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 5 Fridolin Somers 2024-05-23 12:28:11 UTC
Pushed to 23.11.x for 23.11.06
Comment 6 Lucas Gass 2024-05-28 17:47:42 UTC
Backported to 23.05.x for upcoming 23.05.12