Skip to content

Commit

Permalink
Add zipassets.sh to facilitate gzip_static use (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc authored and dajohi committed Sep 23, 2019
1 parent 337cef5 commit debe52f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ controllers/config.go*
testing/
*.orig
debug
public/**/*.gz
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -182,7 +182,8 @@ MySQL> CREATE DATABASE stakepool;
### Nginx/web server

- Adapt sample-nginx.conf or setup a different web server in a proxy
configuration.
configuration. To prepare pre-zipped files to save the reverse proxy the
trouble of compressing data on-the-fly, see the zipassets.sh script.

### stakepoold setup

Expand Down
2 changes: 2 additions & 0 deletions sample-nginx.conf
Expand Up @@ -55,6 +55,8 @@ http {

# Serve static resources directly.
location /assets/* {
# See the zipassets.sh script, which can be used to prepare the
# pre-zipped files used by gzip_static.
gzip_static on; # use .gz files for pre-compressed data
root /opt/dcrstakepool/public;
# Set the Cache-Control and Expires headers for the static assets.
Expand Down
25 changes: 25 additions & 0 deletions zipassets.sh
@@ -0,0 +1,25 @@
#!/bin/bash
#
# This script helps prepare pre-zipped static assets for use with reverse proxy
# features like nginx's gzip_static.

echo "Gzipping assets for use with gzip_static..."
find ./public -type f -name "*.gz" -execdir rm {} \;
# Use GNU parallel if it is installed.
if [ -x "$(command -v parallel)" ]; then
if [ -x "$(command -v 7za)" ]; then
find ./public -type f -not -name "*.gz" | parallel --will-cite --bar 7za a -tgzip -mx=9 -mpass=13 {}.gz {} > /dev/null
else
find ./public -type f -not -name "*.gz" | parallel --will-cite --bar gzip -k9f {} > /dev/null
fi
elif [ -x "$(command -v 7za)" ]; then
find ./public -type f -not -name "*.gz" -execdir 7za a -tgzip -mx=9 -mpass=13 {}.gz {} \; > /dev/null
else
find ./public -type f -not -name "*.gz" -execdir gzip -k9f {} \; > /dev/null
fi

# Clean up incompressible files.
find ./public -type f -name "*.png.gz" -execdir rm {} \;
find ./public -type f -name "*.eot.gz" -execdir rm {} \;
find ./public -type f -name "*.gz.gz" -execdir rm {} \;
find ./public -type f -name "*.woff*.gz" -execdir rm {} \;

0 comments on commit debe52f

Please sign in to comment.