Gzip static module allows you to serve per-compressed files instead of “on the fly” compressed files.
Nginx:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
... server { ... #STATIC FILES location /resources { #access_log off; expires 1d; add_header Cache-Control public; root /usr/share/nginx/html/resources; gzip on; gzip_static on; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; gzip_vary on; } .... } |
Python script
we do need to build the gzip files every time we do update our project. This script will scan all files in resource directory and gzip each file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#!/usr/bin/python import fnmatch import os from os.path import exists resources_path = "/usr/share/nginx/html/resources" for root, dirnames, filenames in os.walk(resources_path): for (filename) in filenames: filename = root + "/" + filename gzip_filename = filename + ".gz" if exists(gzip_filename): os.remove(gzip_filename) os.system('gzip -9 < ' + filename + ' > ' + gzip_filename) |