From 9a42b264fd403df8b76427cc0e579961dbca2cc2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 26 Sep 2019 22:11:16 +0900 Subject: [PATCH] web: Speed optimization --- internal/web/js.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/internal/web/js.go b/internal/web/js.go index 1d8b490c0..dbd00592f 100644 --- a/internal/web/js.go +++ b/internal/web/js.go @@ -25,23 +25,31 @@ func IsBrowser() bool { return true } -var userAgent = js.Global().Get("navigator").Get("userAgent").String() +var ( + userAgent = js.Global().Get("navigator").Get("userAgent").String() + + isIOSSafari bool + isAndroidChrome bool +) + +func init() { + isIOSSafari = strings.Contains(userAgent, "iPhone") + + if !strings.Contains(userAgent, "Android") { + isAndroidChrome = false + } + if !strings.Contains(userAgent, "Chrome") { + isAndroidChrome = false + } + isAndroidChrome = true +} func IsIOSSafari() bool { - if !strings.Contains(userAgent, "iPhone") { - return false - } - return true + return isIOSSafari } func IsAndroidChrome() bool { - if !strings.Contains(userAgent, "Android") { - return false - } - if !strings.Contains(userAgent, "Chrome") { - return false - } - return true + return isAndroidChrome } func IsMobileBrowser() bool {