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
Fiber supports global compression using GZip / Deflate using the [Compression Setting](application.md#settings). But with the `c.Compress()` method you can enable / disable compression within handlers.
227
+
228
+
**Signature**
229
+
230
+
```go
231
+
c.Compress(enable ...bool)
232
+
```
233
+
234
+
**Example**
235
+
236
+
```go
237
+
// Example 1
238
+
funcmain() {
239
+
app:= fiber.New(&fiber.Settings{
240
+
Compression: true, // global compression enabled
241
+
})
242
+
app.Get("/", func(c *fiber.Ctx) {
243
+
c.Send("Hello, World!") // compressed
244
+
})
245
+
app.Get("/demo", func(c *fiber.Ctx) {
246
+
c.Compress(false)
247
+
c.Send("hello, World!") // not compressed
248
+
})
249
+
}
250
+
// Example 2
251
+
funcmain() {
252
+
app:= fiber.New() // compression disabled by default
253
+
app.Get("/", func(c *fiber.Ctx) {
254
+
c.Compress()
255
+
c.Send("Hello, World!") // compressed
256
+
})
257
+
app.Get("/demo", func(c *fiber.Ctx) {
258
+
c.Send("hello, World!") // not compressed
259
+
})
260
+
}
261
+
// Example 3
262
+
funcgzip(c *fiber.Ctx) {
263
+
c.Compress()
264
+
c.Next()
265
+
}
266
+
funcmain() {
267
+
app:= fiber.New() // compression disabled by default
0 commit comments