From 61688a0c6da825ad42729d2246e9de8ce77da5b1 Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 12 Mar 2020 13:00:04 +1000 Subject: [PATCH] improve efficiency for small static files --- common/files.go | 20 +++++++++++++++++++- common/theme.go | 9 +++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/common/files.go b/common/files.go index 187fcc95..d2fbdeb4 100644 --- a/common/files.go +++ b/common/files.go @@ -238,6 +238,15 @@ func (list SFileList) JSTmplInit() error { if err != nil { return err } + // Don't use Gzip if we get meagre gains from it as it takes longer to process the responses + if len(gzipData) >= (len(data) + 150) { + gzipData = nil + } else { + diff := len(data) - len(gzipData) + if diff <= len(data)/100 { + gzipData = nil + } + } // Get a checksum for CSPs and cache busting hasher := sha256.New() @@ -279,7 +288,7 @@ func (list SFileList) Init() error { return err } // Don't use Gzip if we get meagre gains from it as it takes longer to process the responses - if len(gzipData) >= (len(data) + 100) { + if len(gzipData) >= (len(data) + 150) { gzipData = nil } else { diff := len(data) - len(gzipData) @@ -316,6 +325,15 @@ func (list SFileList) Add(path, prefix string) error { if err != nil { return err } + // Don't use Gzip if we get meagre gains from it as it takes longer to process the responses + if len(gzipData) >= (len(data) + 150) { + gzipData = nil + } else { + diff := len(data) - len(gzipData) + if diff <= len(data)/100 { + gzipData = nil + } + } // Get a checksum for CSPs and cache busting hasher := sha256.New() diff --git a/common/theme.go b/common/theme.go index c170a6f3..c7937903 100644 --- a/common/theme.go +++ b/common/theme.go @@ -161,6 +161,15 @@ func (t *Theme) AddThemeStaticFiles() error { if err != nil { return err } + // Don't use Gzip if we get meagre gains from it as it takes longer to process the responses + if len(gzipData) >= (len(data) + 150) { + gzipData = nil + } else { + diff := len(data) - len(gzipData) + if diff <= len(data)/100 { + gzipData = nil + } + } // Get a checksum for CSPs and cache busting hasher := sha256.New()