我有一個帶有 S3 源存盤桶(使用 Cloudformation/SAM 委派資源)的 Cloudfront 分發,它的行為很奇怪。S3 存盤桶僅存盤影像。
每當我通過 src 屬性請求影像時,dev-tools 中的網路選項卡顯示 Cloudfront 資源是快取未命中(即使在反復重繪 后仍然存在)。但是,當通過 Postman 或瀏覽器發送 GET 請求時,重繪 一次后,我開始看到來自相應請求發送者的快取命中。
在客戶端,我將 React 與 styled-components 一起用于影像標簽。沒有附加查詢字串,Cloudfront 也被告知忽略它們。
不確定這是否是我的 Cloudformation 設定的問題或來自服務器的快取回應問題,但任何指導將不勝感激!
我的 template.yaml 檔案:
UserAssetsDistributionIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: 'Origin identity.'
UserAssetsDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: // Domain name removed
Id: user-assets-bucket
S3OriginConfig:
OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/${UserAssetsDistributionIdentity}'
Enabled: 'true'
Comment: Projects microservice to distribute user uploaded assets
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
CachedMethods:
- GET
- HEAD
CachePolicyId: b2884449-e4de-46a7-ac36-70bc7f1ddd6d
TargetOriginId: user-assets-bucket
ViewerProtocolPolicy: allow-all
ViewerCertificate:
AcmCertificateArn: // arn removed
SslSupportMethod: sni-only
MinimumProtocolVersion: TLSv1
Aliases:
- uploads.phazia.com
UserAssetsBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
uj5u.com熱心網友回復:
問題是 Chrome 快取回應標頭以重復請求資源。
Devtools 顯示請求資源的狀態代碼為 200 以及一條(來自磁盤快取)訊息——讓我相信狀態代碼和回應標頭正在被快取。嘗試清除瀏覽器快取并獲得預期的 Cloudfront 標頭。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422516.html
標籤:
