mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
+Compressed IMG files
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cache"
|
||||
"github.com/gofiber/fiber/v2/middleware/compress"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||
"github.com/gofiber/storage/memory/v2"
|
||||
@@ -139,6 +141,18 @@ func (s *Server) Start() {
|
||||
|
||||
srv.Use(recover.New())
|
||||
|
||||
// Add compression middleware for HTML responses (non-static routes)
|
||||
srv.Use(compress.New(compress.Config{
|
||||
Level: compress.LevelBestSpeed, // Fast compression for HTML responses
|
||||
Next: func(c *fiber.Ctx) bool {
|
||||
// Only compress for routes that don't start with static prefixes
|
||||
path := c.Path()
|
||||
return strings.HasPrefix(path, "/assets") ||
|
||||
strings.HasPrefix(path, "/static/pictures/") ||
|
||||
strings.HasPrefix(path, "/img/")
|
||||
},
|
||||
}))
|
||||
|
||||
// INFO: No caching middleware in debug mode to avoid cache issues during development
|
||||
// We cant do it with cach busting the files via ?v=XXX, since we also cache the templates.
|
||||
// TODO: Dont cache static assets, bc storage gets huge on images.
|
||||
|
||||
Reference in New Issue
Block a user