From 987039b0f7b5eda01278be59481161d475836ad0 Mon Sep 17 00:00:00 2001 From: DaX Date: Fri, 31 Oct 2025 03:39:25 +0100 Subject: [PATCH] Optimize frontend deployment with proper cache headers Update deployment script to set appropriate cache-control headers: - HTML files: no-cache to prevent stale content - Next.js static assets: 1 year cache with immutable flag - Other assets: 1 day cache for optimal performance This resolves chronic caching issues with admin panel updates. --- scripts/deploy-frontend.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/scripts/deploy-frontend.sh b/scripts/deploy-frontend.sh index 055b66b..fb84e67 100755 --- a/scripts/deploy-frontend.sh +++ b/scripts/deploy-frontend.sh @@ -39,14 +39,42 @@ fi echo -e "${GREEN}✓ Build completed${NC}" -# Upload to S3 -echo -e "${BLUE}📤 Uploading to S3...${NC}" +# Upload to S3 with proper cache headers +echo -e "${BLUE}📤 Uploading to S3 with optimized cache headers...${NC}" + +# First, delete old files +echo -e "${BLUE} 🗑️ Cleaning old files...${NC}" aws s3 sync out/ s3://$S3_BUCKET/ \ --region $REGION \ --delete \ - --cache-control "public, max-age=3600" + --exclude "*" -echo -e "${GREEN}✓ Files uploaded to S3${NC}" +# Upload HTML files with no-cache (always revalidate) +echo -e "${BLUE} 📄 Uploading HTML files (no-cache)...${NC}" +aws s3 sync out/ s3://$S3_BUCKET/ \ + --region $REGION \ + --exclude "*" \ + --include "*.html" \ + --cache-control "public, max-age=0, must-revalidate" \ + --content-type "text/html" + +# Upload _next static assets with long-term cache (immutable, 1 year) +echo -e "${BLUE} 🎨 Uploading Next.js static assets (1 year cache)...${NC}" +aws s3 sync out/_next/ s3://$S3_BUCKET/_next/ \ + --region $REGION \ + --cache-control "public, max-age=31536000, immutable" + +# Upload other static assets with moderate cache (1 day) +echo -e "${BLUE} 📦 Uploading other assets (1 day cache)...${NC}" +aws s3 sync out/ s3://$S3_BUCKET/ \ + --region $REGION \ + --exclude "*" \ + --exclude "*.html" \ + --exclude "_next/*" \ + --include "*" \ + --cache-control "public, max-age=86400" + +echo -e "${GREEN}✓ All files uploaded to S3 with optimized cache headers${NC}" # Invalidate CloudFront cache echo -e "${BLUE}🔄 Invalidating CloudFront cache...${NC}"