You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a third compression algorithm alongside Brotli and Gzip via the
zstd-jni library. Zstd is enabled by default at level 22 (maximum).
Spring Framework's EncodedResourceResolver does not yet serve .zst
files (spring-projects/spring-framework#36647), so users serving via
Spring's resource chain should set zstdEnabled=false until that change
is released.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+38-2Lines changed: 38 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Compression Maven Plugin
2
2
3
-
A Maven plugin that compresses static resources using [Brotli](https://github.com/google/brotli)and Gzip.
3
+
A Maven plugin that compresses static resources using [Brotli](https://github.com/google/brotli), Gzip, and [Zstandard](https://facebook.github.io/zstd/).
4
4
5
5
## When to use this plugin
6
6
7
-
If your web application serves static resources (JavaScript, CSS, SVG, etc.) and your web server supports serving pre-compressed files, this plugin generates `.br`and `.gz` variants at build time so the server can serve them directly without compressing on every request.
7
+
If your web application serves static resources (JavaScript, CSS, SVG, etc.) and your web server supports serving pre-compressed files, this plugin generates `.br`, `.gz`, and `.zst` variants at build time so the server can serve them directly without compressing on every request.
8
8
9
9
This plugin is designed to work with Spring Framework's `ResourceResolver` chain. The default resource directories and file extensions match Spring Boot's conventions out of the box. See [Spring Boot integration](#spring-boot-integration) for setup details.
10
10
@@ -31,6 +31,9 @@ By default, this compresses all text-based static resource files under Spring Bo
> Note: Spring Framework's `EncodedResourceResolver` does not yet serve pre-compressed `.zst` files. Support is pending in [spring-projects/spring-framework#36647](https://github.com/spring-projects/spring-framework/pull/36647). If you serve assets via Spring's resource chain, set `<zstdEnabled>false</zstdEnabled>` until that change ships in a Spring Framework release.
34
37
35
38
### Example: Custom extensions and directories
36
39
@@ -66,6 +69,22 @@ By default, this compresses all text-based static resource files under Spring Bo
66
69
</configuration>
67
70
```
68
71
72
+
### Example: Disable Zstandard
73
+
74
+
```xml
75
+
<configuration>
76
+
<zstdEnabled>false</zstdEnabled>
77
+
</configuration>
78
+
```
79
+
80
+
### Example: Lower Zstandard level for faster builds
81
+
82
+
```xml
83
+
<configuration>
84
+
<zstdLevel>3</zstdLevel>
85
+
</configuration>
86
+
```
87
+
69
88
### Example: Lower Brotli quality for faster builds
70
89
71
90
```xml
@@ -94,6 +113,8 @@ All configuration parameters can be set either in the plugin `<configuration>` b
|`zstdEnabled`|`compression.zstd.enabled`|`true`| Enable Zstandard compression (see Spring Framework note above) |
117
+
|`zstdLevel`|`compression.zstd.level`|`22`| Zstandard compression level (practical range 1-22) |
97
118
|`skip`|`compression.skip`|`false`| Skip the plugin |
98
119
99
120
### Default file extensions
@@ -116,6 +137,19 @@ The `brotliQuality` parameter controls the trade-off between compression ratio a
116
137
117
138
The default value of 11 gives the best compression. For faster builds (e.g., during development), a lower value like 4-6 may be preferable.
118
139
140
+
### Zstandard level
141
+
142
+
The `zstdLevel` parameter controls the trade-off between compression ratio and build time:
143
+
144
+
| Level | Speed | Compression ratio |
145
+
|---|---|---|
146
+
| 1-3 | Fast | Lower |
147
+
| 4-15 | Moderate | Good |
148
+
| 16-19 | Slow | Better |
149
+
| 20-22 | Very slow ("ultra" mode) | Best |
150
+
151
+
The default value of 22 gives the best compression. Level 3 matches libzstd's own default and produces noticeably faster builds at the cost of a modest reduction in compression ratio. Note that zstd's decompression speed is, by design, largely independent of the compression level used, so a higher level does not slow down clients that serve the resulting `.zst` files.
152
+
119
153
## Spring Boot integration
120
154
121
155
This plugin generates pre-compressed files that Spring Framework's `EncodedResourceResolver` can serve automatically. To enable this, add the following property to your `application.properties`:
When this property is enabled, Spring Boot will look for `.br` or `.gz` variants of the requested resource and serve the compressed version if the client supports it (via the `Accept-Encoding` header).
129
163
164
+
`.zst` support in `EncodedResourceResolver` is pending upstream (see [spring-projects/spring-framework#36647](https://github.com/spring-projects/spring-framework/pull/36647)). Until that change is released, set `<zstdEnabled>false</zstdEnabled>` if you are serving assets via Spring's resource chain.
0 commit comments