Browse Source

Cache for static resource files

Vova Tkach 6 years ago
parent
commit
91c8377d67
1 changed files with 11 additions and 0 deletions
  1. 11 0
      engine/wrapper/static.go

+ 11 - 0
engine/wrapper/static.go

@@ -19,46 +19,57 @@ type tmplDataErrorMsg struct {
 
 func (e *Wrapper) staticResource() bool {
 	if e.R.URL.Path == "/assets/sys/styles.css" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "text/css")
 		(*e.W).Write(Styles.File_assets_sys_styles_css)
 		return true
 	} else if e.R.URL.Path == "/assets/cp/styles.css" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "text/css")
 		(*e.W).Write(Styles.File_assets_cp_styles_css)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/bootstrap.css" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "text/css")
 		(*e.W).Write(Styles.File_assets_sys_bootstrap_css)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/jquery.js" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "application/javascript; charset=utf-8")
 		(*e.W).Write(Scripts.File_assets_sys_jquery_js)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/popper.js" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "application/javascript; charset=utf-8")
 		(*e.W).Write(Scripts.File_assets_sys_popper_js)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/bootstrap.js" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "application/javascript; charset=utf-8")
 		(*e.W).Write(Scripts.File_assets_sys_bootstrap_js)
 		return true
 	} else if e.R.URL.Path == "/assets/cp/scripts.js" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "application/javascript; charset=utf-8")
 		(*e.W).Write(Scripts.File_assets_cp_scripts_js)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/logo.svg" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "image/svg+xml")
 		(*e.W).Write(Others.File_assets_sys_logo_svg)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/bg.png" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "image/png")
 		(*e.W).Write(Images.File_assets_sys_bg_png)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/logo.png" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "image/png")
 		(*e.W).Write(Images.File_assets_sys_logo_png)
 		return true
 	} else if e.R.URL.Path == "/assets/sys/fave.ico" {
+		(*e.W).Header().Set("Cache-Control", "public, max-age=31536000")
 		(*e.W).Header().Set("Content-Type", "image/x-icon")
 		(*e.W).Write(Others.File_assets_sys_fave_ico)
 		return true