Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

bskyweb: cache /static/{images,js} for 1 week, other files for 1 hour

+16 -2
+16 -2
bskyweb/cmd/bskyweb/server.go
··· 137 137 // 138 138 // configure routes 139 139 // 140 - 141 140 // static files 142 141 staticHandler := http.FileServer(func() http.FileSystem { 143 142 if debug { ··· 150 149 } 151 150 return http.FS(fsys) 152 151 }()) 152 + 153 153 e.GET("/robots.txt", echo.WrapHandler(staticHandler)) 154 154 e.GET("/ips-v4", echo.WrapHandler(staticHandler)) 155 155 e.GET("/ips-v6", echo.WrapHandler(staticHandler)) 156 - e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", staticHandler))) 157 156 e.GET("/.well-known/*", echo.WrapHandler(staticHandler)) 158 157 e.GET("/security.txt", func(c echo.Context) error { 159 158 return c.Redirect(http.StatusMovedPermanently, "/.well-known/security.txt") 159 + }) 160 + e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", staticHandler)), func(next echo.HandlerFunc) echo.HandlerFunc { 161 + return func(c echo.Context) error { 162 + path := c.Request().URL.Path 163 + maxAge := 1 * (60 * 60) // default is 1 hour 164 + 165 + // Cache javascript and images files for 1 week, which works because 166 + // they're always versioned (e.g. /static/js/main.64c14927.js) 167 + if strings.HasPrefix(path, "/static/js/") || strings.HasPrefix(path, "/static/images/") { 168 + maxAge = 7 * (60 * 60 * 24) // 1 week 169 + } 170 + 171 + c.Response().Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", maxAge)) 172 + return next(c) 173 + } 160 174 }) 161 175 162 176 // home