Everything you need as a full stack developer

Deploying a Simple Static Site

- Posted in Junior Developer by

TL;DR Learn how to deploy a simple static site, covering the basics of deployment and providing a solid foundation to build upon. A static site serves pre-built HTML, CSS, and JavaScript files directly from a server or CDN, offering benefits like fast loading times, improved security, and easy maintenance. Follow a step-by-step guide to deploy a "Hello World!" site using GitHub Pages, covering preparation, choosing a deployment option, creating a repository, adding site files, configuring GitHub Pages, and deploying the site.

Welcome to the World of Deployment: A Step-by-Step Guide to Deploying a Simple Static Site

As a full-stack developer, you've spent hours crafting a beautiful static site, pouring your heart and soul into every detail. But now, it's time to share your masterpiece with the world. In this article, we'll take you on a journey to deploy your simple static site, covering the basics of deployment and giving you a solid foundation to build upon.

What is a Static Site?

Before we dive in, let's quickly cover what a static site is. A static site is a website that serves pre-built HTML, CSS, and JavaScript files directly from a server or CDN (Content Delivery Network). Unlike dynamic sites, which generate content on the fly using server-side languages like PHP or Ruby, static sites are fast, secure, and easy to maintain.

Why Deploy a Static Site?

Deploying a static site offers numerous benefits, including:

  • Lightning-fast loading times: Since static sites serve pre-built files, they load quickly, providing an excellent user experience.
  • Improved security: With no server-side code, there's less risk of vulnerabilities and attacks.
  • Easy maintenance: Update your site by simply replacing the files – no complex database updates or server configurations required.

Our Example Site: "Hello World!"

To illustrate the deployment process, we'll use a simple "Hello World!" static site. Our site consists of:

  • An index.html file with basic HTML and CSS
  • A styles.css file for styling
  • A script.js file containing JavaScript code

Step 1: Preparing Your Site

Before deployment, ensure your site is ready by following these steps:

  • Create a new folder for your project and add the index.html, styles.css, and script.js files.
  • Write some basic HTML, CSS, and JavaScript code to display "Hello World!" on the page.

Here's our example code:

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hello World!</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <h1 id="hello-world">Hello World!</h1>
    <script src="script.js"></script>
</body>
</html>
/* styles.css */
#hello-world {
    color: blue;
}
// script.js
console.log("Hello World!");

Step 2: Choosing a Deployment Option

You have several options for deploying your static site, including:

  • GitHub Pages: A free service that hosts your site directly from your GitHub repository.
  • Vercel: A popular platform offering fast deployments and CDN integration.
  • Netlify: A comprehensive solution providing continuous deployment, CDN, and more.

For this example, we'll use GitHub Pages.

Step 3: Creating a GitHub Repository

Create a new GitHub repository for your project:

  • Go to GitHub.com and create a new repository with the name "hello-world-static-site".
  • Initialize the repository by adding a README.md file.
  • Clone the repository to your local machine using Git.

Step 4: Adding Your Site Files

Add your site files to the repository:

  • Create a new folder in your cloned repository called static-site.
  • Add the index.html, styles.css, and script.js files to this folder.
  • Commit your changes with a meaningful message, such as "Added static site files".

Step 5: Configuring GitHub Pages

Configure GitHub Pages to host your site:

  • Go to your repository settings on GitHub.
  • Click on the "GitHub Pages" section.
  • Select the static-site branch and /static-site folder as the source for your site.

Step 6: Deploying Your Site

Deploy your site by pushing your changes to GitHub:

  • Commit your changes with a meaningful message, such as "Deployed static site".
  • Push your changes to the remote repository using Git.

Congratulations! You've Deployed Your Static Site!

Visit https://your-username.github.io/hello-world-static-site/ (replace "your-username" with your actual GitHub username) to see your live "Hello World!" static site. Pat yourself on the back – you've successfully deployed a simple static site!

In this article, we've covered the basics of deploying a simple static site using GitHub Pages. From here, you can explore more advanced topics like continuous deployment, SSL certificates, and caching. The world of deployment is vast, but with this foundation, you're ready to take on new challenges and share your creations with the world.

Happy coding!

Key Use Case

Here's a workflow or use-case for a meaningful example:

Create a personal blog to showcase writing skills and share knowledge with others.

  • Step 1: Prepare the site by creating a new folder, adding HTML, CSS, and JavaScript files, and writing basic code to display the blog title and content.
  • Step 2: Choose a deployment option, such as GitHub Pages or Vercel, to host the blog.
  • Step 3: Create a GitHub repository for the project, initialize it with a README file, and clone it locally using Git.
  • Step 4: Add the site files to the repository, commit changes, and push them to the remote repository.
  • Step 5: Configure GitHub Pages to host the site by selecting the branch and folder as the source.
  • Step 6: Deploy the site by pushing changes to GitHub and visiting the live URL.

This workflow demonstrates how to deploy a simple static site, in this case, a personal blog, using GitHub Pages.

Finally

By deploying a simple static site, you're not only sharing your creativity with the world but also providing a seamless user experience through fast loading times and improved security. As you continue to build upon this foundation, you'll unlock new opportunities for growth and connection with others. Whether it's a personal blog or a business portfolio, your static site can become a powerful tool for self-expression and communication.

Recommended Books

• "HTML and CSS: Design and Build Websites" by Jon Duckett • "CSS Pocket Reference" by Eric A. Meyer • "JavaScript: The Definitive Guide" by David Flanagan

Fullstackist aims to provide immersive and explanatory content for full stack developers Fullstackist aims to provide immersive and explanatory content for full stack developers
Backend Developer 103 Being a Fullstack Developer 107 CSS 109 Devops and Cloud 70 Flask 108 Frontend Developer 357 Fullstack Testing 99 HTML 171 Intermediate Developer 105 JavaScript 206 Junior Developer 124 Laravel 221 React 110 Senior Lead Developer 124 VCS Version Control Systems 99 Vue.js 108

Recent Posts

Web development learning resources and communities for beginners...

TL;DR As a beginner in web development, navigating the vast expanse of online resources can be daunting but with the right resources and communities by your side, you'll be well-equipped to tackle any challenge that comes your way. Unlocking the World of Web Development: Essential Learning Resources and Communities for Beginners As a beginner in web development, navigating the vast expanse of online resources can be daunting. With so many tutorials, courses, and communities vying for attention, it's easy to get lost in the sea of information. But fear not! In this article, we'll guide you through the most valuable learning resources and communities that will help you kickstart your web development journey.

Read more

Understanding component-based architecture for UI development...

Component-based architecture breaks down complex user interfaces into smaller, reusable components, improving modularity, reusability, maintenance, and collaboration in UI development. It allows developers to build, maintain, and update large-scale applications more efficiently by creating independent units that can be used across multiple pages or even applications.

Read more

What is a Single Page Application (SPA) vs a multi-page site?...

Single Page Applications (SPAs) load a single HTML file initially, handling navigation and interactions dynamically with JavaScript, while Multi-Page Sites (MPS) load multiple pages in sequence from the server. SPAs are often preferred for complex applications requiring dynamic updates and real-time data exchange, but MPS may be suitable for simple websites with minimal user interactions.

Read more