Added custom cache control headers for static content
This commit is contained in:
+14
-6
@@ -11,7 +11,6 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/Unknwon/macaron"
|
||||
"github.com/codegangsta/cli"
|
||||
@@ -20,6 +19,7 @@ import (
|
||||
_ "github.com/macaron-contrib/session/postgres"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api"
|
||||
"github.com/grafana/grafana/pkg/api/static"
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
"github.com/grafana/grafana/pkg/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
@@ -65,14 +65,22 @@ func newMacaron() *macaron.Macaron {
|
||||
}
|
||||
|
||||
func mapStatic(m *macaron.Macaron, dir string, prefix string) {
|
||||
m.Use(macaron.Static(
|
||||
headers := func(c *macaron.Context) {
|
||||
c.Resp.Header().Set("Cache-Control", "public max-age: 3600")
|
||||
}
|
||||
|
||||
if setting.Env == setting.DEV {
|
||||
headers = func(c *macaron.Context) {
|
||||
c.Resp.Header().Set("Cache-Control", "max-age: 0")
|
||||
}
|
||||
}
|
||||
|
||||
m.Use(httpstatic.Static(
|
||||
path.Join(setting.StaticRootPath, dir),
|
||||
macaron.StaticOptions{
|
||||
httpstatic.StaticOptions{
|
||||
SkipLogging: true,
|
||||
Prefix: prefix,
|
||||
Expires: func() string {
|
||||
return time.Now().UTC().Format(http.TimeFormat)
|
||||
},
|
||||
AddHeaders: headers,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user