sketch: compress JS and CSS
We noticed that our JS bundles weren't compressed; let's compress them.
Sketch did most of the work here itself, but there's some nonsense
around the fact that we pass a zip.Reader around, which can't seek.
We're probably doing more work than strictly necessary on the server side.
Add gzip compression for JS and source map files in esbuild
- Added compression for .js and .js.map files in the esbuild Build() function
- Gzipped files are created alongside the originals with .gz extension
- This allows for compressed asset serving when supported by clients
Co-Authored-By: sketch
Add support for serving pre-compressed JS and source map files
- Created a custom HTTP handler for /static/ path
- Handler checks if requested JS/JS.map files have gzipped versions
- Serves gzipped files with proper Content-Encoding headers when available
- Falls back to original files when compressed versions are not found
- Client support for gzip encoding is verified through Accept-Encoding header
Co-Authored-By: sketch
Extend gzip compression to include CSS files
- Added CSS files to the compression list alongside JS and source map files
- Added debug output to show which files are being compressed
- Updated error messages to reflect the inclusion of CSS files
Co-Authored-By: sketch
Fix variable naming in Accept-Encoding header processing
- Renamed 'header' variable to 'encoding' for better semantics when processing Accept-Encoding headers
- Addresses gopls check issue in compressed file handler
Co-Authored-By: sketch
Simplify Accept-Encoding header processing
- Simplified check for gzip support using strings.Contains()
- More efficient approach than splitting and iterating
- Addresses gopls efficiency recommendation
Co-Authored-By: sketch
Extract compressed file handler to separate package
- Created a new package loop/server/gzhandler
- Moved compressedFileHandler implementation to the new package
- Renamed to Handler for better Go idioms
- Updated loophttp.go to use the new package
- Improved modularity and separation of concerns
Co-Authored-By: sketch
Enhance gzhandler and add test coverage
- Updated gzhandler to handle all files except .gz files
- Added comprehensive test suite for gzhandler
- Removed debug print from esbuild.go
- Tests different file types, browsers with and without gzip support
- Tests directory handling
Co-Authored-By: sketch
Fix 'seeker can't seek' error in gzhandler
- Changed approach to read gzipped file into memory before serving
- Avoids io.Seeker interface requirement for http.ServeContent
- Fixes 500 error when serving compressed JavaScript files
- Added missing io import
Co-Authored-By: sketch
diff --git a/loop/server/loophttp.go b/loop/server/loophttp.go
index 0253f6d..0660357 100644
--- a/loop/server/loophttp.go
+++ b/loop/server/loophttp.go
@@ -19,6 +19,8 @@
"syscall"
"time"
+ "sketch.dev/loop/server/gzhandler"
+
"github.com/creack/pty"
"sketch.dev/ant"
"sketch.dev/loop"
@@ -340,7 +342,7 @@
}
})
- s.mux.Handle("/static/", http.StripPrefix("/static/", http.FileServerFS(webBundle)))
+ s.mux.Handle("/static/", http.StripPrefix("/static/", gzhandler.New(webBundle)))
// Terminal WebSocket handler
// Terminal endpoints - predefined terminals 1-9