Speed improvements

This commit is contained in:
Florian Hoss 2022-10-20 11:58:22 +02:00
parent 8fd60df29d
commit 2f18aa3d68
5 changed files with 12 additions and 8 deletions

View file

@ -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,
}))

View file

@ -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,

View file

@ -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))

View file

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

View file

@ -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>