Bug 36531 - Koha should serve text/javascript compressed, like application/javascript is
Summary: Koha should serve text/javascript compressed, like application/javascript is
Status: Pushed to oldoldstable
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Phil Ringnalda
QA Contact: Testopia
URL:
Keywords:
Depends on: 36463
Blocks:
  Show dependency treegraph
 
Reported: 2024-04-05 02:42 UTC by Phil Ringnalda
Modified: 2024-11-15 00:40 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00,23.11.06,23.05.12
Circulation function:


Attachments
Bug 36531: Serve text/javascript compressed, like application/javascript is (3.71 KB, patch)
2024-04-05 02:53 UTC, Phil Ringnalda
Details | Diff | Splinter Review
Bug 36531: Serve text/javascript compressed, like application/javascript is (3.75 KB, patch)
2024-04-05 10:32 UTC, David Nind
Details | Diff | Splinter Review
Bug 36531: Serve text/javascript compressed, like application/javascript is (3.81 KB, patch)
2024-04-08 11:55 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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 (lukeg) 2024-05-28 17:47:42 UTC
Backported to 23.05.x for upcoming 23.05.12