-
Notifications
You must be signed in to change notification settings - Fork 17
Gzip Compression
Grasshopper allows compression of responses using Gzip. Enabling compression for your entire application is as simple as adding the below line to your application's startup code. This enables compression for both static and dynamic responses.
gh.addFilters('/', gh.gzipFilter);
The above method has 2 drawbacks while serving static files.
- The
content-length
header of the response will not be set as compression is performed on the fly. - Every request will use CPU cycles for performing the compression on same content.
Static files can be optionally pre-compressed to avoid these drawbacks. The pre-compressed files should be placed on the same location as original static files and must be named the same as original file with '.gz' suffixed. This will save the compression CPU cycles on static requests and also allows determining content-length. However, you'd want to leave uncompressed versions of the files to be served to clients without gzip support.
All files under your static files directory can be pre-compressed with these commands.
for f in `find . -type f | grep -v '.gz$'`
do
gzip -c $f > $f.gz
done