Skip to content

gzip compress assets and images - #1884

Merged
kaikreuzer merged 1 commit into
openhab:mainfrom
joerg1985:compressed-assets
Mar 8, 2026
Merged

gzip compress assets and images#1884
kaikreuzer merged 1 commit into
openhab:mainfrom
joerg1985:compressed-assets

Conversation

@joerg1985

Copy link
Copy Markdown
Contributor

This PR will enable gzip compression for /assets/* and /images/* with more mime types.
In the past the precompressed files where used, but this is currently broken and a deprecated Jetty feature.
So i does not make sense for me to fix using the precompressed files, as the support has been removed in Jetty 10+.

Before the 5 MB javascript was not compressed:
grafik

Now the 5 MB file is compressed to 1.16 MB
grafik

Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
@joerg1985
joerg1985 requested a review from a team as a code owner March 7, 2026 19:13
@kaikreuzer

Copy link
Copy Markdown
Member

In the past the precompressed files were used

Do they still exist anywhere and should they now be removed?

@kaikreuzer kaikreuzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kaikreuzer
kaikreuzer merged commit e0fddfe into openhab:main Mar 8, 2026
2 checks passed
@kaikreuzer kaikreuzer added the enhancement An enhancement or new feature label Mar 8, 2026
@kaikreuzer kaikreuzer added this to the 5.2 milestone Mar 8, 2026
@dilyanpalauzov

Copy link
Copy Markdown
Contributor

openhab/openhab-webui#2481 and openhab/openhab-webui#1432 was/is supposed to alter the webserver to deliver compressed files, when the browser announces support for these with Accept-Encoding: gzip, deflate, br.

The changes in openhab/openhab-webui#1521 were not sufficient to make openHAB deliver pre-compressed .js files.

Is this change now delivering the compressed files, and:

  • are files compressed when requested,
  • are files compressed when openHAB is built?

@joerg1985

Copy link
Copy Markdown
Contributor Author

are files compressed when requested,
Yes

are files compressed when openHAB is built?
Yes, there ist still code in the webui repo related handing the precompressed files.

@dilyanpalauzov

Copy link
Copy Markdown
Contributor

are files compressed when requested,

Yes

The question was if the files are compressed on the fly. With openHAB 5.2.0 build 5227 my observation is that indeed many things are returned gziz-compressed, which previously used no compression. But HTML responses for /overview and GET /auth ` are returned uncompressed:

  • This returns 12.6kb uncompressed:
curl 'https://192.168.0.12:8443/auth?response_type=code&client_id=https%3A%2F%2F192.168.0.12%3A8443&redirect_uri=https%3A%2F%2F192.168.0.12%3A8443&scope=admin&code_challenge_method=S256&code_challenge=DPABCd83nDxcDsk-uuuqkhjAbSTut5ez9Jsl2HlTiL3M&state=ead8465uuuu \
  -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'cache-control: no-cache' \
  -H 'pragma: no-cache' \
  -H 'priority: u=0, i' \
  -H 'referer: https://192.168.0.12:8443/overview/' \
  -H 'sec-ch-ua: "Chromium";v="145", "Not:A-Brand";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Linux"' \
  -H 'sec-fetch-dest: document' \
  -H 'sec-fetch-mode: navigate' \
  -H 'sec-fetch-site: same-origin' \
  -H 'sec-fetch-user: ?1' \
  -H 'upgrade-insecure-requests: 1' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36' \
  --insecure
  • This returns 4.0kb uncompressed
curl 'https://192.168.0.12:8443/overview/' \
  -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'cache-control: no-cache' \
  -b 'X-OPENHAB-SESSIONID=88a5210c-6a0a-4912-8d6e-255631001d76' \
  -H 'pragma: no-cache' \
  -H 'priority: u=0, i' \
  -H 'sec-ch-ua: "Chromium";v="145", "Not:A-Brand";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Linux"' \
  -H 'sec-fetch-dest: document' \
  -H 'sec-fetch-mode: navigate' \
  -H 'sec-fetch-site: none' \
  -H 'sec-fetch-user: ?1' \
  -H 'upgrade-insecure-requests: 1' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36' \
  --insecure

@joerg1985

Copy link
Copy Markdown
Contributor Author

I think the best would be not to use a include list of paths and mime types, instead using an exclude list for mime types. So only some image types can get excluded.

@dilyanpalauzov

Copy link
Copy Markdown
Contributor

When I look in org.openhab.ui-5.2.0-SNAPSHOT.jar from openHAB built 5229 I see that app/assets/index-BC_AFnOV.js and app/assets/openhab-logo-BcJrHiEZ.svg are included three times: uncompressed, with .gz and with .br file extension. But in the browser they are delivered only as gzip. Even if reorder the Accept-Encoding: gzip, deflate, br, zstd to have gzip after br or not to have gzip, the br compressed files are never returned.

If formats will be excluded, then .woff and .woff2 should be excluded too, as these are already compressed.

In BasicUI the returned js/css files are not delivered compressed.

Thinking on this again, it is actually fine to compress some data when MainUI/BasicUI are built, and deliver these files compressed to browsers. Everything else can be compressed on the fly, when the resource is requested, by a HTTP proxy between the internet and openHAB. (The latter does not work, if openHAB acts without a HTTP proxy, but is accessed from internet by using VPN).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants