You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# This script is used to upload static build assets (JS, CSS, ...) and public static files (public folder) to a CDN.
6
+
# We're using Cloudflare R2 as CDN.
7
+
# By using a CDN, we can serve static assets extremely fast while saving big time on egress costs.
8
+
# An alternative is proxying via CF, but that comes with Orange-To-Orange issues (Cloudflare having issues with Cloudflare) and increased latency as there is a double TLS termination.
9
+
# The script is only supposed to run on production deployments and is not run on any previews.
10
+
11
+
# By using a dynamic path including the env, app and commit hash, we can ensure that there are no conflicts.
12
+
# Static assets from previous deployments stick around for a while to ensure there are no "downtimes".
13
+
14
+
# Advantages of the CDN approach we're using:
15
+
16
+
# Get rid of egress costs for static assets across our apps on Vercel
17
+
# Disable CF proxying and get around these odd timeouts issues
18
+
# Save ~20ms or so for asset requests, as there is no additional CF proxying and we avoid terminating SSL twice
19
+
# Always hits the CDN, gonna be super quick
20
+
# Does not run on local or preview environments, only on staging/prod deployments
21
+
# There are no other disadvantages - you don't have to consider it when developing locally, previews still work, everything on Vercel works as we're used to
22
+
23
+
#######
24
+
25
+
# If asset CDN is specifically disabled (i.e. studio self-hosted), we skip
26
+
if [[ "$FORCE_ASSET_CDN"=="-1" ]];then
27
+
echo"Skipping asset upload. Set FORCE_ASSET_CDN=1 or VERCEL_ENV=production to execute."
28
+
exit 0
29
+
fi
30
+
31
+
# Check for force env var or production environment
32
+
if [[ "$FORCE_ASSET_CDN"!="1" ]] && [[ "$VERCEL_ENV"!="production" ]];then
33
+
echo"Skipping asset upload. Set FORCE_ASSET_CDN=1 or VERCEL_ENV=production to execute."
34
+
exit 0
35
+
fi
36
+
37
+
# Set the cdnBucket variable based on NEXT_PUBLIC_ENVIRONMENT
38
+
if [[ "$NEXT_PUBLIC_ENVIRONMENT"=="staging" ]];then
0 commit comments