@@ -6,12 +6,12 @@ import (
66 "encoding/base64"
77 "errors"
88 "fmt"
9- "github.com/lightningnetwork/lnd/lncfg"
109 "io/ioutil"
1110 "net"
1211 "net/http"
1312 "os"
1413 "path/filepath"
14+ "regexp"
1515 "strings"
1616 "sync"
1717 "time"
@@ -24,6 +24,7 @@ import (
2424 "github.com/lightninglabs/loop/loopd"
2525 "github.com/lightninglabs/loop/looprpc"
2626 "github.com/lightningnetwork/lnd"
27+ "github.com/lightningnetwork/lnd/lncfg"
2728 "github.com/lightningnetwork/lnd/lnrpc"
2829 "github.com/lightningnetwork/lnd/lntest/wait"
2930 "github.com/lightningnetwork/lnd/macaroons"
@@ -460,7 +461,16 @@ func (g *Shushtar) startGrpcWebProxy() error {
460461 // something we don't know in which case the static file server
461462 // will answer with a 404.
462463 log .Infof ("Handling static file request: %s" , req .URL .Path )
463- staticFileServer .ServeHTTP (resp , req )
464+ // add 1-year cache header for static files. React uses content-based
465+ // hashes in file names, so when any file is updated, the url will
466+ // change causing the browser cached version to be invalidated
467+ var re = regexp .MustCompile (`^\/(static|fonts|icons)\/.*` )
468+ if re .MatchString (req .URL .Path ) {
469+ resp .Header ().Set ("Cache-Control" , "max-age=31536000" )
470+ }
471+ // transfer static files using gzip to save up to 70% of bandwidth
472+ gzipHandler := makeGzipHandler (staticFileServer .ServeHTTP )
473+ gzipHandler (resp , req )
464474 }
465475
466476 // Create and start our HTTPS server now that will handle both gRPC web
0 commit comments