浏览代码

Speed improvements

Florian Hoss 2 年之前
父节点
当前提交
2f18aa3d68
共有 5 个文件被更改,包括 12 次插入8 次删除
  1. 3 2
      server/middlewares.go
  2. 1 0
      server/routes.go
  3. 1 0
      server/static.go
  4. 0 4
      static/css/global.css
  5. 7 2
      templates/_base.gohtml

+ 3 - 2
server/middlewares.go

@@ -14,14 +14,15 @@ func setupMiddlewares(router *chi.Mux) {
 		router.Use(newStructuredLogger(logger))
 	}
 	router.Use(middleware.Recoverer)
+	router.Use(middleware.AllowContentEncoding("deflate", "gzip"))
 	router.Use(middleware.RealIP)
 	router.Use(middleware.CleanPath)
 	router.Use(middleware.RedirectSlashes)
-	router.Use(middleware.Compress(5, "text/html", "text/css", "text/js"))
+	router.Use(middleware.Compress(5, "text/html", "text/css"))
 	router.Use(cors.Handler(cors.Options{
 		AllowedOrigins:   []string{"https://*", "http://*"},
 		AllowedMethods:   []string{"GET", "OPTIONS"},
-		AllowedHeaders:   []string{"Content-Type"},
+		AllowedHeaders:   []string{"Accept-Encoding", "Content-Type"},
 		AllowCredentials: false,
 		MaxAge:           300,
 	}))

+ 1 - 0
server/routes.go

@@ -14,6 +14,7 @@ type LaunchpadInformation struct {
 }
 
 func launchpad(w http.ResponseWriter, r *http.Request) {
+	w.Header().Set("Content-Type", "text/html")
 	files.ParseHtml(w, "index.gohtml", LaunchpadInformation{
 		Title:     "Launchpad",
 		Bookmarks: bookmark.Bookmarks,

+ 1 - 0
server/static.go

@@ -25,6 +25,7 @@ func fileServer(r chi.Router, path string, root http.FileSystem) {
 	path += "*"
 
 	r.Get(path, func(w http.ResponseWriter, r *http.Request) {
+		w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
 		rctx := chi.RouteContext(r.Context())
 		pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*")
 		fs := http.StripPrefix(pathPrefix, http.FileServer(root))

+ 0 - 4
static/css/global.css

@@ -1,4 +0,0 @@
-.link:hover .img {
-  opacity: 1;
-  transition: opacity ease-in 0.2s;
-}

+ 7 - 2
templates/_base.gohtml

@@ -5,6 +5,7 @@
       <meta charset="UTF-8" />
       <title>{{ template "title" . }}</title>
       <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+      <meta name="description" content="A blazing fast start-page for services written in Go " />
 
       <link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon.png" />
       <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon/favicon-32x32.png" />
@@ -13,8 +14,12 @@
       <link rel="mask-icon" href="/static/favicon/safari-pinned-tab.svg" color="#1e293b" />
       <meta name="msapplication-TileColor" content="#da532c" />
       <meta name="theme-color" content="#da532c" />
-
-      <link rel="stylesheet" href="/static/css/global.css" />
+      <style>
+        .link:hover .img {
+          opacity: 1;
+          transition: opacity ease-in 0.2s;
+        }
+      </style>
       <link rel="stylesheet" href="/static/css/style.css" />
     </head>