我通过 aws 命令部署静态应用程序。我通过以下命令将所有文件从我的文件夹复制到 s3 存储桶:
aws s3 sync C:\app s3://myBucket
我想将内容编码设置为 gzip,仅用于 js、jpg 和 html 文件。我通过此命令成功为所有文件夹执行此操作:--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 提供服务的速度改进很小。