我通过aws命令部署静态应用程序。 我通过以下命令将文件夹中的所有文件复制到 s3 存储桶:
aws s3 sync C:\app s3://myBucket
我想将 js、jpg 和 html 文件的内容编码设置为 gzip。
我成功地通过此命令对所有文件夹执行此操作: --content-encoding gzip
我怎样才能只针对特定的文件类型呢?
最佳答案
这已经很旧了,但我需要找到一种方法来做到这一点:我没有使用 Cloudfront,并且我们使用的代理不处理 gzip...所以:
- 排除所有文件
- 根据需要包含各个文件类型
- 设置适当的编码/选项
下面我还添加了访问控制和缓存控制,并删除了 s3 中本地目录中不存在的所有文件
我已经将 JS/CSS 与所有图像、html 分开,但这可能没有必要。
但是,由于没有为每个单独的 --include 显式设置内容编码/缓存,我确实遇到了很多麻烦,因此我将其设置如下以使其更清晰。
我能找到的 AWS 文档没有提到任何这些东西
aws s3 sync ./dist/ s3://{bucket} \
--exclude "*" \
--include "static/*.ico" --acl "public-read" --cache-control no-cache \
--include "static/*.png" --acl "public-read" --cache-control no-cache \
--include "*.html" --acl "public-read" --cache-control no-cache \
--include "static/img/*.svg" --acl "public-read" --cache-control no-cache \
--delete \
aws s3 sync ./dist/ s3://{bucket} \
--exclude "*" \
--include "static/js/*.js" --acl "public-read" --cache-control no-cache --content-encoding gzip \
--include "static/css/*.css" --acl "public-read" --cache-control no-cache --content-encoding gzip \
--delete \
仅从 s3 提供服务的速度有相当巧妙的小提升。
关于amazon-s3 - 通过 aws 命令将内容编码设置为特定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165946/