This is what we do, although we don't use query strings as some network appliances don't respect them with respect to caching.
We use a virtual directory instead:
Where <git version> is obtained like this:
$ git log --oneline | wc -l | awk '{ print $1; }'
And nginx removes the virtual directory like this:
location ~ /static/([0-9]+)/ {
rewrite ^/static/([0-9]+)/(.+)$ /static/$2 last;
}
Static files are cached for a year:
location /static {
alias {{ web_static_dir }};
expires 1y;
add_header Cache-Control "no-transform,public,max-age=31557600,s-maxage=31557600";
gzip on;
}
So a static file will be cached "forever" unless we do a release, at which point the virtual directory changes to the new version and clients start requesting (to them) a completely new static file.
Also note we don't copy to S3 as there's no way to do the virtual directory without having a real directory for every release. CloudFront will read files from a web site as well, and we don't need the extra deployment complexity.
Regards,
-scott