Taking your website live with free, fast, and secure Cloudflare Pages hosting
Before we dive into Cloudflare Pages, let's understand how a static website makes its way from a server to your browser:
When you type a website URL (like www.pet-adoption.com) and press Enter, your browser sends a request to find that website.
The Domain Name System (DNS) works like a phone book, translating the human-friendly URL into an IP address (like 192.168.1.1) where the website is hosted.
Your browser connects to the web server at that IP address and asks for the website files.
The server sends back HTML, CSS, JavaScript, images, and other static files that make up the website.
Your browser processes these files and displays the complete website on your screen.
The structure and content of your pages
Styling and visual appearance
Interactive functionality
Images, videos, fonts, and other media
Folder structure and file relationships
Key Point: All of these files are pre-built and don't change unless you update your code and redeploy. Once a user loads your page, they already have everything they need for the entire experience.
Several factors affect how quickly your website loads for visitors:
The farther a user is from your server, the longer it takes for data to travel.
Larger files (especially images) take longer to download and display.
A single server can become overwhelmed with too many visitors at once.
SSL encryption adds security but requires extra processing.
A modern platform for deploying static websites:
Your website is automatically distributed across Cloudflare's global network of data centers, ensuring your visitors get fast page loads no matter where they are.
Automatic HTTPS for all your sites with no configuration required. The padlock icon in browsers gives visitors confidence in your site's security.
Connect to GitHub, GitLab, or Bitbucket repositories for automatic deployments whenever you push changes to your code.
The deployment process simplified:
Link your GitHub/GitLab repository containing your website files to Cloudflare Pages.
Specify how your site should be built (usually not needed for simple HTML/CSS sites).
Cloudflare automatically builds and deploys your website to its global network.
Future changes pushed to your repository trigger automatic rebuilds and deployments.
Key advantages for developers and clients:
What can be deployed on Cloudflare Pages:
Perfect for Cloudflare Pages
Needs additional services
Note: Many static site generators (like Next.js, Gatsby, Hugo) can create fully-featured websites that still deploy as static sites. Cloudflare Pages supports all major frameworks.
Preparing your code for Cloudflare deployment:
If you don't already have an account, create one at github.com.
Click the "+" icon in the top right of GitHub and select "New repository".
GitHub's new repository form
Click "Create repository" to finalize setup.
Organizing your files for deployment:
my-website/
│
├── index.html # Your homepage
├── about.html # About page
├── contact.html # Contact page
├── assets/ # Folder for static assets
│ ├── css/ # Stylesheets
│ │ └── style.css
│ ├── js/ # JavaScript files
│ │ └── main.js
│ └── images/ # Image files
│ ├── logo.png
│ └── hero.jpg
├── .gitignore # Files to exclude from Git
└── README.md # Information about the project
index.html.gitignore file for excluding temporary filesREADME.md explaining your projectAdding your code to GitHub:
Easiest for beginners
More powerful approach
# Command line approach
# Clone your repository
git clone https://github.com/username/my-website.git
# Navigate to the repository
cd my-website
# Copy your website files into this folder
# (done manually or with cp/copy commands)
# Add all files to git
git add .
# Commit the changes
git commit -m "Initial website upload"
# Push to GitHub
git push origin main
Problems that can affect deployment:
Using paths like /images/logo.png instead of images/logo.png or ./images/logo.png
Fix: Use relative paths in all HTML, CSS, and JavaScript files
Not having an index.html file in the root directory
Fix: Ensure your main page is named index.html at the root
Using Images/logo.png in code but having images/logo.png in files
Fix: Be consistent with casing in all file references
Adding large files, temporary files, or sensitive information
Fix: Use a .gitignore file to exclude non-essential files
Taking your site from repository to live:
Create a free account at dash.cloudflare.com/sign-up if you don't already have one.
In the Cloudflare dashboard, click on "Pages" in the left sidebar.
Cloudflare dashboard with Pages section highlighted
Click "Create a project" and select "Connect Git" to link with your GitHub repository.
Follow the prompts to connect your GitHub account and authorize Cloudflare access.
Choose the repository containing your website from the list.
For a simple HTML site, you can often leave the defaults unchanged.
Cloudflare Pages build settings form
Customizing deployment options:
| Setting | Description | Typical Value |
|---|---|---|
| Production branch | The branch to use for the live site | main or master |
| Build command | Command to build the site (if needed) | Empty for static HTML, npm run build for React |
| Build output directory | Where built files are located | / for static HTML, build or dist for frameworks |
| Root directory | Directory containing source code | / (repository root) |
| Environment variables | Settings for build process | Usually empty for simple sites |
React (Create React App):
npm run buildbuildNext.js:
npm run buildout (for static export)Final steps to go live:
Click "Save and Deploy" to start the deployment process.
Cloudflare will show you a build log. Wait for the process to complete.
Cloudflare Pages build log
Once finished, Cloudflare provides a URL where your site is live (typically your-project.pages.dev).
Click the provided URL to see your live website!
Connecting your own domain name:
Buy a domain from any registrar (GoDaddy, Namecheap, Google Domains, etc.).
In your Cloudflare Pages project, click on "Custom domains" tab.
Click "Set up a custom domain" and enter your domain name.
Follow Cloudflare's instructions to update your domain's DNS settings.
Tip: For the simplest setup, consider transferring your domain to Cloudflare's own domain registrar service, which integrates seamlessly with Pages.
Updating your site after deployment:
Update your HTML, CSS, or other files locally.
Commit changes and push to your GitHub repository.
Cloudflare automatically detects the changes and rebuilds your site.
Understanding the journey of a web page from server to browser, how DNS works, and the difference between traditional hosting and CDN distribution.
The benefits of using Cloudflare Pages for hosting websites, including the global CDN, free SSL certificates, and Git integration.
How to create and organize a GitHub repository with proper structure for deployment, and common pitfalls to avoid.
Step-by-step process for deploying a website, configuring build settings, and setting up continuous deployment for future updates.
Congratulations on completing the entire AI for Website Development course! You now have the skills to:
Continue your journey by:
Thank you for joining us on this journey through AI-powered web development!