Skip to content

Commit 7459184

Browse files
committed
Optimize build for Azure Front Door with cache-busting
- Configure Vite for optimal cache-busting with content-based hashes - Generate unique filenames for JS/CSS: assets/[name]-[hash].[ext] - Organize images with hash: assets/images/[name]-[hash].[ext] - Update nginx config with proper cache headers for Front Door: * 1 year cache for hashed assets (immutable) * 30 days cache for non-hashed static assets * No cache for HTML files - Support ES2022 target for modern browsers with top-level await - Enable source maps for debugging - Add Azure Front Door documentation This ensures: ✅ Automatic cache invalidation on new deployments ✅ Optimal CDN performance with long cache times ✅ No manual cache purging needed ✅ Browser always gets latest version after deployment
1 parent c04b025 commit 7459184

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

editor/AZURE-FRONTDOOR.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Azure Front Door Cache Configuration
2+
3+
This application is optimized for Azure Front Door with proper cache-busting and CDN configuration.
4+
5+
## Cache Strategy
6+
7+
### Immutable Assets (Long Cache - 1 year)
8+
- **JavaScript**: `/assets/*-[hash].js` - Cached for 1 year with `immutable` flag
9+
- **CSS**: `/assets/*-[hash].css` - Cached for 1 year with `immutable` flag
10+
- **Images**: `/assets/images/*-[hash].*` - Cached for 1 year with `immutable` flag
11+
12+
### Semi-Static Assets (Medium Cache - 30 days)
13+
- **Images without hash**: `*.png, *.jpg, *.svg` etc. - Cached for 30 days
14+
15+
### Dynamic Content (No Cache)
16+
- **HTML**: `*.html` - Never cached, always fresh from origin
17+
- **Service Worker**: Always fresh
18+
19+
## Build Process
20+
21+
Every build generates:
22+
- Unique filenames with content-based hashes
23+
- Source maps for debugging
24+
- Optimized bundles for modern browsers (ES2022)
25+
26+
## Azure Front Door Benefits
27+
28+
1. **Automatic Cache Invalidation**: New builds get new filenames, so no manual cache purging
29+
2. **Global CDN**: Assets served from edge locations worldwide
30+
3. **Compression**: Gzip/Brotli compression for smaller payloads
31+
4. **HTTP/2**: Faster loading with multiplexed connections
32+
33+
## Build Version Indicator
34+
35+
The app includes a build version indicator in the top-right corner showing:
36+
- Version number
37+
- Git commit hash (7 chars)
38+
- Build timestamp
39+
40+
This helps verify which version is currently deployed and when cache updates take effect.

editor/nginx.conf

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,30 @@ http {
1717
try_files $uri $uri/ /index.html;
1818
}
1919

20-
# Cache static assets
21-
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
20+
# Cache hashed assets (JS/CSS with hash in filename) - long cache
21+
location ~* /assets/.*-[a-f0-9]+\.(js|css)$ {
2222
expires 1y;
2323
add_header Cache-Control "public, immutable";
24+
add_header X-Content-Type-Options "nosniff";
25+
}
26+
27+
# Cache images with hash - long cache
28+
location ~* /assets/images/.*-[a-f0-9]+\.(png|jpg|jpeg|gif|ico|svg|webp)$ {
29+
expires 1y;
30+
add_header Cache-Control "public, immutable";
31+
}
32+
33+
# Cache other static assets without hash - shorter cache
34+
location ~* \.(png|jpg|jpeg|gif|ico|svg|webp)$ {
35+
expires 30d;
36+
add_header Cache-Control "public";
37+
}
38+
39+
# Don't cache the main HTML file
40+
location ~* \.html$ {
41+
expires -1;
42+
add_header Cache-Control "no-cache, no-store, must-revalidate";
43+
add_header Pragma "no-cache";
2444
}
2545
}
2646
}

editor/vite.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,27 @@ import react from '@vitejs/plugin-react';
44
export default defineConfig({
55
plugins: [react()],
66
root: '.',
7+
build: {
8+
// Ensure proper cache-busting for Azure Front Door
9+
rollupOptions: {
10+
output: {
11+
// Generate unique filenames with hash for cache-busting
12+
entryFileNames: 'assets/[name]-[hash].js',
13+
chunkFileNames: 'assets/[name]-[hash].js',
14+
assetFileNames: (assetInfo) => {
15+
// Keep images in their own folder with hash
16+
if (assetInfo.name?.match(/\.(png|jpe?g|svg|gif|webp|ico)$/i)) {
17+
return 'assets/images/[name]-[hash][extname]';
18+
}
19+
// CSS and other assets with hash
20+
return 'assets/[name]-[hash][extname]';
21+
},
22+
},
23+
},
24+
// Ensure proper source maps for debugging
25+
sourcemap: true,
26+
// Optimize for Azure Front Door (support top-level await)
27+
target: 'es2022',
28+
minify: 'esbuild',
29+
},
730
});

0 commit comments

Comments
 (0)