CLOUD
Guides

CDN: How It Speeds Up Your Site and How to Set It Up

CLOUD|February 20, 2026|4 min read|471 views
CDN: How It Speeds Up Your Site and How to Set It Up

CDN distributes your content across servers worldwide. Visitors load from the nearest point. We explain setup with Cloudflare — for free.

What Is a CDN and Why Do You Need It?

A CDN (Content Delivery Network) is a geographically distributed network of servers that stores copies of your site's content and delivers it to users from the nearest point. Instead of every request traveling to your origin server in Riyadh, a user in London or Dubai receives content from the nearest CDN server to them.

Quantified CDN Benefits

1. Higher Speed

  • Reduces physical distance between user and content
  • A user in London gets your images from a European server, not Riyadh
  • Improves Core Web Vitals (LCP specifically)

2. Reduced Load on Your Origin Server

  • CDN absorbs 70-90% of requests
  • Your origin server only handles dynamic data requests
  • Bandwidth savings of up to 80%

3. DDoS Protection

  • CDN absorbs DDoS attacks instead of your origin server
  • Attack distributed across the CDN network

4. Higher Uptime

  • If your server has a problem, CDN continues serving static content
  • Automatic failover

Best CDN Options for Saudi Arabia

Cloudflare (Most Powerful and Cost-Effective)

# No server installation - everything done through DNS
# 1. Go to dash.cloudflare.com
# 2. Add your site
# 3. Change Name Servers to point to Cloudflare
# 4. Done

Free plan: Sufficient for most sites

  • Global CDN
  • Free SSL
  • Basic DDoS protection
  • Analytics

Pro plan ($20/month): For serious sites

  • Image optimization
  • Mobile optimization
  • Advanced WAF

Bunny CDN (Cheaper for High Volume)

# Price: $0.01/GB for data (after 500GB free)
# Very simple setup

سحابة أمريكية CloudFront (For Enterprise)

# More expensive but more flexible
# Suitable if already using سحابة أمريكية

Cloudflare Setup Step by Step

Step 1: Register Your Site

# No code - everything through Cloudflare dashboard
# dash.cloudflare.com → Add Site → enter your domain

Step 2: Configure Cache Rules

# Page Rules in Cloudflare
# Path Action
/static/* Cache Everything, Edge Cache TTL: 1 month
/images/* Cache Everything, Edge Cache TTL: 1 week
*.css Cache Everything, Edge Cache TTL: 1 week
*.js Cache Everything, Edge Cache TTL: 1 week
/api/* Bypass Cache
/portal/* Bypass Cache

Step 3: Configure Cache Headers in nginx

# /etc/nginx/conf.d/cache.conf
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf)$ {
 expires 1y;
 add_header Cache-Control "public, immutable";
 add_header Vary "Accept-Encoding";
}

location ~* \.(html|xml|txt)$ {
 expires 1h;
 add_header Cache-Control "public, must-revalidate";
}

Step 4: Enable Compression

# In nginx.conf
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
 text/plain
 text/css
 text/javascript
 application/javascript
 application/json
 image/svg+xml;

CDN with Laravel

// config/filesystems.php
// Route assets to CDN URL
'url' => env('CDN_URL', env('APP_URL')),
# .env
CDN_URL=https://cdn.yoursite.com
// In Blade templates
// Instead of asset('/css/app.css')
// Will produce: https://cdn.yoursite.com/css/app.css
asset('/css/app.css')
// vite.config.js - CDN for production
export default defineConfig({
 build: {
 rollupOptions: {
 output: {
 // Hash in filename for cache busting
 entryFileNames: 'js/[name]-[hash].js',
 chunkFileNames: 'js/[chunk]-[hash].js',
 assetFileNames: 'assets/[name]-[hash].[ext]',
 }
 }
 }
});

Measuring CDN Impact

# Before CDN - measure latency from a remote location
curl -w "@curl-format.txt" -o /dev/null -s https://yoursite.com/image.jpg

# Create curl-format.txt file
cat > curl-format.txt << 'EOF'
 time_namelookup: %{time_namelookup}s\n
 time_connect: %{time_connect}s\n
 time_appconnect: %{time_appconnect}s\n
 time_pretransfer: %{time_pretransfer}s\n
 time_redirect: %{time_redirect}s\n
 time_starttransfer: %{time_starttransfer}s\n
 ----------\n
 time_total: %{time_total}s\n
EOF

Expected Results

Metric Without CDN With Cloudflare Free
LCP (Largest Contentful Paint) 3-5s 1-2s
Bandwidth consumed 100% 20-30%
TTFB for static content 200-500ms 20-80ms
Google PageSpeed improvement - +15-30 points

Important Notes

Content NOT suitable for CDN:

  • Payment and checkout pages
  • User portal (/portal/*)
  • API endpoints
  • Any page containing user-specific data

Content suitable for CDN:

  • Product images
  • Built CSS and JS
  • Fonts
  • Public PDF and document files
  • Static landing pages

Integration with cloud.net.sa Servers

cloud.net.sa provides servers in Riyadh and Jeddah with latency very low latency within Saudi Arabia. When using CDN with cloud.net.sa servers, you get the best of both worlds: speed within Saudi Arabia from local servers, and speed outside from the CDN network.

Summary

A CDN is not a luxury — it is an investment in user experience. Cloudflare Free is sufficient to start and costs nothing. Setup takes an hour and its impact is immediate and lasting.


Get Started

Want to try it yourself? Choose the right hosting plan or build your custom server with the specs you need.

Share