<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Web Hosting on kenji.blog</title><link>http://kenji.blog/en/categories/web-hosting/</link><description>Recent content in Web Hosting on kenji.blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>kenjinote</copyright><lastBuildDate>Sat, 12 Sep 2026 12:00:00 +0900</lastBuildDate><atom:link href="http://kenji.blog/en/categories/web-hosting/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Publish a Hugo Blog for Free and Extremely Fast with Cloudflare Pages or GitHub Pages</title><link>http://kenji.blog/en/p/hugo-hosting-cloudflare-vs-github-pages/</link><pubDate>Sat, 12 Sep 2026 12:00:00 +0900</pubDate><guid>http://kenji.blog/en/p/hugo-hosting-cloudflare-vs-github-pages/</guid><description>&lt;img src="http://kenji.blog/p/hugo-hosting-cloudflare-vs-github-pages/img/eyecatch.jpg" alt="Featured image of post How to Publish a Hugo Blog for Free and Extremely Fast with Cloudflare Pages or GitHub Pages" />&lt;p>When running a website or blog, page speed (performance), operational costs, and security are extremely important factors. In the past, the combination of dynamic CMS (Content Management System) like WordPress and shared hosting was the mainstream, but currently, an architecture known as &amp;lsquo;Jamstack&amp;rsquo; is gaining significant attention. Among them, by combining &amp;ldquo;Hugo&amp;rdquo;, an ultra-fast static site generator (SSG) built in Go, with modern hosting services like Cloudflare Pages and GitHub Pages, it is possible to build a &lt;strong>completely free and blazing fast&lt;/strong> blog environment.&lt;/p>
&lt;p>In this article, we will delve very deeply from a technical perspective into the specific steps to publish a Hugo-based static site with Cloudflare Pages and GitHub Pages, the architectural differences between each platform, the construction of CI/CD (Continuous Integration / Continuous Deployment) using GitHub Actions, DNS optimization, caching strategies, and even the introduction of privacy-friendly web analytics.&lt;/p>
&lt;hr>
&lt;h2 id="1-basics-of-static-site-generators-ssg-and-jamstack">1. Basics of Static Site Generators (SSG) and Jamstack
&lt;/h2>&lt;h3 id="11-why-static-sites">1.1 Why static sites?
&lt;/h3>&lt;p>Traditional dynamic CMS (e.g., WordPress) issue queries to a database (such as MySQL) and dynamically generate HTML on the server-side (like PHP) to return for every user request. While this method offers high flexibility, it has low resilience against sudden traffic spikes (such as going viral or DDoS attacks) and often leads to complicated infrastructure configurations, like placing cache servers (Redis or Varnish) in the front end.&lt;/p>
&lt;p>On the other hand, with Static Site Generators (SSG) adopting the Jamstack (JavaScript, APIs, and Markup) architecture, all HTML files, CSS, and JavaScript are generated in advance (at build time). In response to user requests, the web server (or CDN) simply returns the already generated static files as they are, thereby achieving overwhelming speed and robust security.&lt;/p>
&lt;h3 id="12-the-superiority-of-hugo">1.2 The Superiority of Hugo
&lt;/h3>&lt;p>There are various choices for SSGs such as Next.js, Gatsby, Jekyll, and Astro, but the greatest feature of Hugo is its &lt;strong>build speed&lt;/strong>. Benefiting from concurrent processing in the Go language, building even a site with thousands to tens of thousands of pages is completed in just a few seconds. This significantly reduces wait times in CI/CD pipelines and directly connects to an improved Developer Experience (DX).&lt;/p>
&lt;hr>
&lt;h2 id="2-comparison-of-hosting-service-architectures">2. Comparison of Hosting Service Architectures
&lt;/h2>&lt;p>Where to host the static files generated by Hugo becomes the next challenge. Representative choices include Cloudflare Pages, GitHub Pages, and Netlify, but each has a different network architecture behind it.&lt;/p>
&lt;h3 id="21-cdn-and-edge-computing">2.1 CDN and Edge Computing
&lt;/h3>&lt;p>All of these platforms use globally distributed CDNs (Content Delivery Networks) to deliver content. However, beyond just caching static files, the ability to perform request routing and header rewriting at the PoP (Point of Presence) closest to the user through &amp;ldquo;edge computing&amp;rdquo; serves as a differentiating factor.&lt;/p>
&lt;pre class="mermaid">
graph TD
A[&amp;#34;User (Tokyo)&amp;#34;] --&amp;gt;|Low Latency| B[&amp;#34;Edge Node (NRT)&amp;#34;]
C[&amp;#34;User (New York)&amp;#34;] --&amp;gt;|Low Latency| D[&amp;#34;Edge Node (EWR)&amp;#34;]
E[&amp;#34;User (London)&amp;#34;] --&amp;gt;|Low Latency| F[&amp;#34;Edge Node (LHR)&amp;#34;]
B --&amp;gt; G[&amp;#34;Origin Storage / Object Store&amp;#34;]
D --&amp;gt; G
F --&amp;gt; G
&lt;/pre>
&lt;h3 id="22-github-pages">2.2 GitHub Pages
&lt;/h3>&lt;p>GitHub Pages is a service that allows you to publish HTML, CSS, and JavaScript files directly from a GitHub repository. CDNs like Fastly are used behind the scenes, delivering sufficient performance. However, there are constraints on header customization (e.g., setting &lt;code>Cache-Control&lt;/code> or security headers), and redirect settings rely on HTML meta refresh or Jekyll plugins, making its functions as pure infrastructure somewhat modest.&lt;/p>
&lt;h3 id="23-cloudflare-pages">2.3 Cloudflare Pages
&lt;/h3>&lt;p>Cloudflare Pages is a static site hosting service built on top of Cloudflare&amp;rsquo;s world-class Anycast network (deployed in over 275 cities). It enables overwhelming performance tuning, including standard support for HTTP/3 (QUIC), image optimization, and integration with edge functions (Cloudflare Workers). Additionally, a major benefit is that there are no bandwidth charges, so it can be operated for free no matter how much traffic spikes.&lt;/p>
&lt;h3 id="24-netlify">2.4 Netlify
&lt;/h3>&lt;p>Netlify is a pioneer of Jamstack, offering an all-in-one DX that integrates form features, authentication (Identity), serverless functions, and more. However, exceeding the free tier bandwidth (100GB per month) incurs expensive pay-as-you-go billing, so careful cost management is necessary for blogs that heavily use images and videos.&lt;/p>
&lt;hr>
&lt;h2 id="3-theoretical-calculation-of-performance-and-latency-mathematical-model-with-latex">3. Theoretical Calculation of Performance and Latency (Mathematical Model with LaTeX)
&lt;/h2>&lt;p>In evaluating web performance, reducing latency is the most important metric. Let&amp;rsquo;s model how much latency is reduced by using a CDN (edge) compared to accessing the origin server directly.&lt;/p>
&lt;p>Let the probability that a user&amp;rsquo;s request hits the cache be the &amp;ldquo;Cache Hit Ratio&amp;rdquo;, denoted as $C$. It follows $0 \le C \le 1$.
Let the latency to the origin server be $L_{origin}$, and the latency to the nearest edge node be $L_{edge}$.&lt;/p>
&lt;p>The new average latency $L_{new}$ is calculated as the following expected value:&lt;/p>
$$ L_{new} = C \times L_{edge} + (1 - C) \times (L_{edge} + L_{origin}) $$&lt;p>Simplifying this formula yields the following:&lt;/p>
$$ L_{new} = L_{edge} + (1 - C) \times L_{origin} $$&lt;p>For example, when a user in Tokyo accesses an origin server located on the East Coast of the US (New York), considering the physical distance of the fiber optics and the processing delays at routers, $L_{origin}$ will be roughly 200 ms. On the other hand, by using a CDN like Cloudflare, they can connect to an edge node in Tokyo, reducing $L_{edge}$ to about 10 ms.&lt;/p>
&lt;p>Assuming a cache hit ratio $C = 0.95$ (95%),&lt;/p>
$$ L_{new} = 10 + (1 - 0.95) \times 200 = 10 + 0.05 \times 200 = 10 + 10 = 20 \text{ ms} $$&lt;p>In this way, introducing a CDN can dramatically reduce (by about 90%) the average latency from 210 ms to 20 ms.&lt;/p>
&lt;hr>
&lt;h2 id="4-building-a-cicd-pipeline-using-github-actions">4. Building a CI/CD Pipeline using GitHub Actions
&lt;/h2>&lt;p>To automate the update process for a Hugo blog, we will build a CI/CD pipeline using GitHub Actions. With this setup, simply writing a Markdown article locally and running &lt;code>git push&lt;/code> will automatically trigger the build and deploy to Cloudflare Pages or GitHub Pages.&lt;/p>
&lt;p>The sequence diagram below shows the entire flow from pushing an article to delivering it to the user.&lt;/p>
&lt;pre class="mermaid">
sequenceDiagram
participant U as &amp;#34;User (Author)&amp;#34;
participant G as &amp;#34;GitHub Repo&amp;#34;
participant A as &amp;#34;GitHub Actions&amp;#34;
participant C as &amp;#34;Cloudflare Pages&amp;#34;
participant V as &amp;#34;Visitor&amp;#34;
U-&amp;gt;&amp;gt;G: &amp;#34;git push origin main&amp;#34;
G-&amp;gt;&amp;gt;A: &amp;#34;Trigger Push Event&amp;#34;
A-&amp;gt;&amp;gt;A: &amp;#34;Checkout &amp;amp; Setup Hugo&amp;#34;
A-&amp;gt;&amp;gt;A: &amp;#34;hugo --minify (Build)&amp;#34;
A-&amp;gt;&amp;gt;C: &amp;#34;Deploy to Cloudflare Pages (Direct Upload)&amp;#34;
C--&amp;gt;&amp;gt;A: &amp;#34;Deployment URL (Success)&amp;#34;
V-&amp;gt;&amp;gt;C: &amp;#34;Request Web Page&amp;#34;
C--&amp;gt;&amp;gt;V: &amp;#34;Return Cached HTML (Edge)&amp;#34;
&lt;/pre>
&lt;h3 id="41-deployment-settings-for-cloudflare-pages-direct-upload">4.1 Deployment Settings for Cloudflare Pages (Direct Upload)
&lt;/h3>&lt;p>Cloudflare Pages offers two methods: linking a GitHub repository to build on Cloudflare&amp;rsquo;s infrastructure, or using &amp;ldquo;Direct Upload&amp;rdquo; for static files built via GitHub Actions. If you want to manage Hugo versions more strictly and integrate with other jobs (such as testing and image optimization), building on GitHub Actions and using the Direct Upload method is recommended.&lt;/p>
&lt;p>Below is a practical example of &lt;code>.github/workflows/deploy.yml&lt;/code> for deploying to Cloudflare Pages.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Deploy Hugo site to Cloudflare Pages&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">on&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">push&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">branches&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="s2">&amp;#34;main&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">workflow_dispatch&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">jobs&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">build-and-deploy&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">runs-on&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;ubuntu-latest&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">steps&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Checkout repository&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">uses&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;actions/checkout@v4&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">with&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">submodules&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;recursive&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">fetch-depth&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">0&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Setup Hugo&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">uses&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;peaceiris/actions-hugo@v3&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">with&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">hugo-version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;0.125.0&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">extended&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Build Hugo Site&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">run&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;hugo --minify --gc&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">env&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">HUGO_ENVIRONMENT&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;production&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Deploy to Cloudflare Pages&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">uses&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;cloudflare/pages-action@v1&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">with&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">apiToken&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">${{ secrets.CLOUDFLARE_API_TOKEN }}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">accountId&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">${{ secrets.CLOUDFLARE_ACCOUNT_ID }}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">projectName&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;your-project-name&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">directory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;public&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">gitHubToken&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">${{ secrets.GITHUB_TOKEN }}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">branch&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;main&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>In this pipeline, HTML/CSS/JS are minified using the &lt;code>--minify&lt;/code> option, and unnecessary files are removed with &lt;code>--gc&lt;/code>. These are the basics of performance optimization.&lt;/p>
&lt;hr>
&lt;h2 id="5-deep-dive-into-dns-settings-custom-domains-and-cname--alias-records">5. Deep Dive into DNS Settings: Custom Domains and CNAME / ALIAS Records
&lt;/h2>&lt;p>When using a custom domain (e.g., &lt;code>kenji.blog&lt;/code>), proper configuration of DNS (Domain Name System) is essential.&lt;/p>
&lt;h3 id="51-cname-record-limitations-and-zone-apex">5.1 CNAME Record Limitations and Zone Apex
&lt;/h3>&lt;p>Typically, when pointing a subdomain (e.g., &lt;code>www.kenji.blog&lt;/code>) to an external service, a &lt;code>CNAME&lt;/code> record is used. However, according to DNS specifications (RFC 1034), a &lt;code>CNAME&lt;/code> record cannot be set on the root domain (also known as the Zone Apex or naked domain, e.g., &lt;code>kenji.blog&lt;/code>). This is due to the rule that the Zone Apex must contain an SOA (Start of Authority) record, NS (Name Server) records, or MX (Mail Exchange) records, and a CNAME cannot coexist with other resource records.&lt;/p>
&lt;h3 id="52-solutions-alias--aname--cname-flattening">5.2 Solutions: ALIAS / ANAME / CNAME Flattening
&lt;/h3>&lt;p>To solve this problem, modern DNS providers offer their own extended features.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>ALIAS / ANAME Records&lt;/strong>: The DNS server dynamically resolves the name and returns the final A record (IP address) to the client. Amazon Route 53 and others support this.&lt;/li>
&lt;li>&lt;strong>CNAME Flattening&lt;/strong>: A feature provided by Cloudflare. It behaves as if a CNAME were set on the Zone Apex, while Cloudflare&amp;rsquo;s authoritative DNS servers transparently return a group of automatically resolved IP addresses (A and AAAA records) to the client.&lt;/li>
&lt;/ul>
&lt;p>When using Cloudflare Pages, delegating the domain&amp;rsquo;s name servers to Cloudflare and utilizing this &amp;ldquo;CNAME Flattening&amp;rdquo; results in the most seamless and high-performance setup.&lt;/p>
&lt;hr>
&lt;h2 id="6-caching-strategies-and-http-header-control">6. Caching Strategies and HTTP Header Control
&lt;/h2>&lt;p>Another key element in accelerating static sites is the &amp;ldquo;caching strategy&amp;rdquo;. In Cloudflare Pages, you can use the generated file (&lt;code>_headers&lt;/code> file) to control HTTP response headers in detail.&lt;/p>
&lt;h3 id="61-edge-cache-vs-browser-cache">6.1 Edge Cache vs Browser Cache
&lt;/h3>&lt;p>Caches can broadly be divided into two types: &amp;ldquo;Edge Cache&amp;rdquo; held on the CDN side, and &amp;ldquo;Browser Cache&amp;rdquo; saved in the user&amp;rsquo;s browser.&lt;/p>
&lt;p>For static files (such as images, CSS, and JS, whose filenames include hashes), it is ideal to let the browser cache them for a long time. On the other hand, to reflect updates immediately in HTML files, it is common to keep their browser cache short (or disabled) and serve them from the edge cache.&lt;/p>
&lt;p>Configuration example of &lt;code>_headers&lt;/code> in Cloudflare Pages:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl"># Do not browser-cache HTML files, validate them every time
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">/*.html
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Cache-Control: public, max-age=0, must-revalidate
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Let the browser cache asset files (CSS/JS/images) for 1 year
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">/assets/*
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Cache-Control: public, max-age=31536000, immutable
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">/img/*
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Cache-Control: public, max-age=31536000, immutable
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="62-calculation-formula-for-bandwidth-cost-reduction">6.2 Calculation Formula for Bandwidth Cost Reduction
&lt;/h3>&lt;p>By setting appropriate cache headers, the volume of data transferred from the server (edge) can be greatly reduced. The monthly bandwidth cost $Cost$ is represented by the following model, based on the transfer volume $B_i$ of each resource, the cache hit ratio $C_i$, and the unit price of bandwidth $R$:&lt;/p>
$$ Cost = \sum_{i=1}^{n} \left( B_i \times (1 - C_i) \times R \right) $$&lt;p>Because outbound data transfer is free with Cloudflare ($R = 0$), the direct financial cost becomes $0$. However, when using other infrastructures like GitHub Pages alongside it, or when using something like AWS S3 as a backend, maximizing this cache hit ratio $C_i$ is crucial for reducing infrastructure costs.&lt;/p>
&lt;hr>
&lt;h2 id="7-web-analytics-balancing-privacy-and-performance">7. Web Analytics Balancing Privacy and Performance
&lt;/h2>&lt;p>Running a blog inevitably requires web analytics to understand how many users are visiting. Google Analytics (GA4) has long been the de facto standard, but with recent trends in privacy protection (such as GDPR and CCPA) and the phase-out of third-party cookies, the situation is changing.&lt;/p>
&lt;h3 id="71-impact-on-web-performance">7.1 Impact on Web Performance
&lt;/h3>&lt;p>Introducing Google Analytics (specifically &lt;code>gtag.js&lt;/code> or Google Tag Manager) leads to the loading and execution of numerous external scripts, negatively impacting performance (especially TTFB and main thread blocking time).&lt;/p>
&lt;p>Let&amp;rsquo;s break down site loading times as follows:&lt;/p>
&lt;pre class="mermaid">
pie title Typical Site Loading Times Breakdown
&amp;#34;TTFB (Time to First Byte)&amp;#34; : 15
&amp;#34;Content Download (HTML/CSS)&amp;#34; : 20
&amp;#34;DOM Parsing &amp;amp; Rendering&amp;#34; : 45
&amp;#34;Analytics &amp;amp; Third-party JS&amp;#34; : 20
&lt;/pre>
&lt;p>It is not uncommon for third-party JS analytics tools to account for around 20% to 30% of total load times.&lt;/p>
&lt;h3 id="72-introducing-cloudflare-web-analytics">7.2 Introducing Cloudflare Web Analytics
&lt;/h3>&lt;p>This is where privacy-first, cookieless web analytics tools like Cloudflare Web Analytics and Plausible Analytics are gaining attention.&lt;/p>
&lt;p>Cloudflare Web Analytics works just by embedding a very lightweight JavaScript snippet, and since it doesn&amp;rsquo;t issue cookies, there&amp;rsquo;s no need to install annoying Cookie Consent Banners.&lt;/p>
&lt;p>Implementation in Hugo is also very simple. Just add the provided snippet to &lt;code>layouts/partials/head.html&lt;/code> or &lt;code>layouts/partials/analytics.html&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">{{ if eq hugo.Environment &amp;#34;production&amp;#34; }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">&amp;lt;!-- Cloudflare Web Analytics --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">script&lt;/span> &lt;span class="na">defer&lt;/span> &lt;span class="na">src&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#39;https://static.cloudflareinsights.com/beacon.min.js&amp;#39;&lt;/span> &lt;span class="na">data-cf-beacon&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#39;{&amp;#34;token&amp;#34;: &amp;#34;YOUR_CLOUDFLARE_BEACON_TOKEN&amp;#34;}&amp;#39;&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;/&lt;/span>&lt;span class="nt">script&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">&amp;lt;!-- End Cloudflare Web Analytics --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{{ end }}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Adding the &lt;code>defer&lt;/code> attribute allows the script to load asynchronously without blocking HTML parsing, letting it run after the DOM is built. This minimizes its impact on initial display speed (LCP: Largest Contentful Paint and FCP: First Contentful Paint).&lt;/p>
&lt;hr>
&lt;h2 id="8-conclusion-and-best-practices">8. Conclusion and Best Practices
&lt;/h2>&lt;p>When running static sites using Hugo, adopting modern hosting platforms like Cloudflare Pages or GitHub Pages provides overwhelming benefits across cost performance, load speed, and security.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Blazing Fast Builds&lt;/strong>: Leverage Hugo&amp;rsquo;s speed to minimize CI/CD pipeline (GitHub Actions) execution times.&lt;/li>
&lt;li>&lt;strong>Edge Delivery&lt;/strong>: Utilize Cloudflare&amp;rsquo;s edge network to deliver content to global users with millisecond-level latency.&lt;/li>
&lt;li>&lt;strong>Appropriate DNS Configuration&lt;/strong>: Make use of CNAME Flattening to safely and swiftly operate your Zone Apex (custom domain).&lt;/li>
&lt;li>&lt;strong>Caching Strategy Optimization&lt;/strong>: Use &lt;code>_headers&lt;/code> to properly separate browser cache and edge cache based on resource type.&lt;/li>
&lt;li>&lt;strong>Lightweight Analytics&lt;/strong>: Adopt privacy-friendly analytics like Cloudflare Web Analytics that won&amp;rsquo;t compromise performance.&lt;/li>
&lt;/ol>
&lt;p>By combining these, it is possible to build a scalable, robust blog system for free that can withstand massive traffic of several million PVs per month. If you are considering launching a tech blog, corporate site, or portfolio site, be sure to try out this Jamstack + Hugo + Cloudflare Pages setup.&lt;/p></description></item></channel></rss>