<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 静亭雅苑</title>
    <description>The latest articles on DEV Community by 静亭雅苑 (@whjin).</description>
    <link>https://dev.to/whjin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4139420%2Ff1780af7-3bc7-41fd-8edc-51e55a796fde.png</url>
      <title>DEV Community: 静亭雅苑</title>
      <link>https://dev.to/whjin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/whjin"/>
    <language>en</language>
    <item>
      <title>Self-Hosted Image Hosting: GitHub Private Repo, Cloud Server, and Cloudflare DNS Proxy</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 07:55:47 +0000</pubDate>
      <link>https://dev.to/whjin/self-hosted-image-hosting-github-private-repo-cloud-server-and-cloudflare-dns-proxy-lao</link>
      <guid>https://dev.to/whjin/self-hosted-image-hosting-github-private-repo-cloud-server-and-cloudflare-dns-proxy-lao</guid>
      <description>&lt;h1&gt;
  
  
  Self-Hosted Image Hosting: GitHub Private Repo, Cloud Server, and Cloudflare DNS Proxy
&lt;/h1&gt;

&lt;p&gt;Every blog hits the same wall eventually: your image hosting stops being "good enough." For me the wall was literal — half my readers couldn't load the images at all. This article covers the image hosting setup I ended up with on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;: a GitHub &lt;strong&gt;private&lt;/strong&gt; repository as the source of truth, a mainland cloud server as the origin, and Cloudflare DNS proxying in front of it. It's a near-free architecture, it's fast for both Chinese and overseas visitors, and it has survived real traffic. Here's how it works and the exact pitfalls to avoid.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why a GitHub CDN stopped being enough
&lt;/h2&gt;

&lt;p&gt;My blog images originally lived in a GitHub repository and were served through GitHub's public CDN (jsDelivr / &lt;code&gt;raw.githubusercontent.com&lt;/code&gt;). That's a classic zero-cost setup and it works fine — for overseas readers.&lt;/p&gt;

&lt;p&gt;Two things broke it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;raw.githubusercontent.com&lt;/code&gt; is blocked in mainland China.&lt;/strong&gt; Open the browser console on a page loading such images and you see &lt;code&gt;ERR_CONNECTION_RESET&lt;/code&gt;. No retry, no fallback — the images simply vanish for a huge share of your audience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The audience mix is real.&lt;/strong&gt; Although the site's content is English-oriented, most of its current visitors are from mainland China. Any solution that sacrifices their experience to optimize for everyone else is the wrong trade.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The tempting fix — "just put Cloudflare's free CDN in front of it" — doesn't work either: the free Cloudflare plan has &lt;strong&gt;no mainland China edge nodes&lt;/strong&gt;. Proxying a mainland origin through an overseas edge makes domestic visitors &lt;em&gt;slower&lt;/em&gt;, not faster (their traffic leaves China and comes back). That's the exact opposite of what you want.&lt;/p&gt;

&lt;p&gt;So the requirements were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Images served from a &lt;strong&gt;mainland origin&lt;/strong&gt; for domestic visitors (fast, and the domain is already ICP-registered, so this is legal and clean).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Overseas visitors&lt;/strong&gt; still get an edge cache, so they don't hammer a tiny server's bandwidth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git keeps being the source of truth&lt;/strong&gt; — versioning, backup, and a clean sync path to the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GitHub private repo (yourname/your-images)
        │  git clone
        ▼
Aliyun ECS (mainland, low-spec)  →  /var/www/img-origin
        │  Nginx: only /images/ is public
        ▼
img.yourdomain.com  (subdomain)
        │  Cloudflare DNS proxy (orange cloud)
        ▼
Visitors: domestic → mainland origin directly; overseas → Cloudflare edge cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each layer has exactly one job. GitHub stores and versions the images. The server serves them. Cloudflare proxies and caches for the non-mainland half of the world. HTTPS is handled with a certbot certificate validated through Cloudflare's DNS API.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: Keep images in a private GitHub repo
&lt;/h2&gt;

&lt;p&gt;The repo is &lt;strong&gt;private&lt;/strong&gt; on purpose. It contains private assets that aren't meant for public browsing — I don't want the raw directory browsable by anyone. GitHub gives me three things for free: version history, off-site backup, and an easy way to sync the server (&lt;code&gt;git pull&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Practical rules that saved me pain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep &lt;strong&gt;one image directory&lt;/strong&gt; (&lt;code&gt;/images/&lt;/code&gt;) and nothing else that matters in the web root. The repo also holds the deploy scripts, but Nginx must never serve them (more below).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.gitignore&lt;/code&gt; the things that must never be committed: API key files (&lt;code&gt;.env&lt;/code&gt;), macOS metadata (&lt;code&gt;._*&lt;/code&gt;, &lt;code&gt;.DS_Store&lt;/code&gt;), and anything local. &lt;code&gt;git status&lt;/code&gt; is your friend — verify what actually lands in the repo before pushing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Clone to the server and lock Nginx down
&lt;/h2&gt;

&lt;p&gt;SSH into the server, clone the repo, and point Nginx at the checkout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone git@github.com:yourname/your-images.git /var/www/img-origin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Nginx config is where "self-hosted" either becomes safe or becomes a liability. The whole trick is &lt;strong&gt;deny by default, allow one directory&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server_name&lt;/span&gt; &lt;span class="s"&gt;img.yourdomain.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="n"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kn"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;301&lt;/span&gt; &lt;span class="s"&gt;https://&lt;/span&gt;&lt;span class="nv"&gt;$host$request_uri&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;   &lt;span class="c1"&gt;# force HTTPS&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;443&lt;/span&gt; &lt;span class="s"&gt;ssl&lt;/span&gt; &lt;span class="s"&gt;http2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server_name&lt;/span&gt; &lt;span class="s"&gt;img.yourdomain.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kn"&gt;root&lt;/span&gt; &lt;span class="n"&gt;/var/www/img-origin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;# deny hidden files and directories (.git, .env, ...)&lt;/span&gt;
    &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="p"&gt;~&lt;/span&gt; &lt;span class="sr"&gt;/\.&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kn"&gt;deny&lt;/span&gt; &lt;span class="s"&gt;all&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# deny everything else in the repo root (scripts, README, ...)&lt;/span&gt;
    &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="n"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kn"&gt;deny&lt;/span&gt; &lt;span class="s"&gt;all&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# the only public directory&lt;/span&gt;
    &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="n"&gt;/images/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kn"&gt;try_files&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kn"&gt;expires&lt;/span&gt; &lt;span class="s"&gt;7d&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kn"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;Cache-Control&lt;/span&gt; &lt;span class="s"&gt;"public,&lt;/span&gt; &lt;span class="s"&gt;max-age=604800"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kn"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;X-Frame-Options&lt;/span&gt; &lt;span class="s"&gt;SAMEORIGIN&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;X-Content-Type-Options&lt;/span&gt; &lt;span class="s"&gt;nosniff&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server_tokens&lt;/span&gt; &lt;span class="no"&gt;off&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;autoindex&lt;/span&gt; &lt;span class="no"&gt;off&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The details that matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only &lt;code&gt;/images/&lt;/code&gt; is open.&lt;/strong&gt; A repo checkout contains &lt;code&gt;.git&lt;/code&gt;, &lt;code&gt;.env&lt;/code&gt;, deploy scripts — all of it is denied. &lt;code&gt;location ~ /\.&lt;/code&gt; catches hidden files before any prefix match can leak them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;7-day cache&lt;/strong&gt; on images. Your readers' browsers stop re-fetching; the origin's tiny bandwidth is used only for cache misses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redirect 80 → 443&lt;/strong&gt; so no one ever loads the image host over plain HTTP.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security headers&lt;/strong&gt; and &lt;code&gt;server_tokens off&lt;/code&gt; are cheap hygiene for a public host.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Cloudflare DNS proxy — orange cloud, on purpose
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;wuhuajin.com&lt;/code&gt;'s DNS is hosted at Cloudflare. The decision I had to defend was &lt;strong&gt;whether the new &lt;code&gt;img.yourdomain.com&lt;/code&gt; record should be proxied (orange cloud) or DNS-only (gray cloud)&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Gray cloud (DNS-only)&lt;/strong&gt; is fastest for domestic visitors — they resolve straight to the mainland origin, no Cloudflare hop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Orange cloud (proxied)&lt;/strong&gt; gives overseas visitors the Cloudflare edge cache, which keeps their traffic off the server's 1 Mbps uplink entirely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a mixed audience I chose &lt;strong&gt;orange cloud&lt;/strong&gt;: &lt;code&gt;A img.yourdomain.com → 203.0.113.10&lt;/code&gt; with proxying enabled. Domestic users still reach a mainland origin quickly (Cloudflare routes them to the nearest available path), and overseas users get cached edge delivery. The 1 Mbps origin is protected from the global traffic. If the audience were 100% domestic, gray cloud would be right; if it were 100% overseas, a full CDN would be right. Mixed audience → proxied record.&lt;/p&gt;

&lt;p&gt;Two Cloudflare-specific rules I learned the hard way:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Only add records; don't touch the existing ones.&lt;/strong&gt; The domain already had a set of records for the main site, subdomains, and Workers. Add the new &lt;code&gt;img&lt;/code&gt; record, verify with &lt;code&gt;dig&lt;/code&gt;, and leave everything else alone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never flip the global SSL/TLS mode for one host.&lt;/strong&gt; SSL mode (e.g. "Full (strict)") is a &lt;strong&gt;domain-level&lt;/strong&gt; setting — changing it affects every proxied record, including your main site. Keep the recommended automatic mode and let Cloudflare upgrade traffic progressively. The origin still gets its own real certificate (next step), which is what actually matters.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 4: HTTPS with certbot, DNS-01 validation
&lt;/h2&gt;

&lt;p&gt;The origin certificate is issued with certbot using &lt;strong&gt;DNS-01 validation&lt;/strong&gt; through Cloudflare's API. Why DNS-01 instead of the usual HTTP-01?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No open port or webroot needed — it validates by creating a TXT record.&lt;/li&gt;
&lt;li&gt;It works even when the record is behind Cloudflare's proxy.&lt;/li&gt;
&lt;li&gt;It's wildcard-ready if you ever need it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Setup is three small pieces. First, a credentials file on the server (single line, no quotes):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;dns_cloudflare_api_token&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;your_real_api_token_here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;600 ~/.secrets/cloudflare-credentials.ini   &lt;span class="c"&gt;# the token is a secret, protect it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then issue the certificate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;certbot certonly &lt;span class="nt"&gt;--dns-cloudflare&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--dns-cloudflare-credentials&lt;/span&gt; ~/.secrets/cloudflare-credentials.ini &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; img.yourdomain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Point the Nginx SSL directives at the certbot output paths, run &lt;code&gt;nginx -t&lt;/code&gt;, then reload. certbot's automatic renewal handles everything after that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Cut over the URLs
&lt;/h2&gt;

&lt;p&gt;The last step is the one people forget: &lt;strong&gt;update every existing reference&lt;/strong&gt;. My site keeps its navigation and link data in &lt;code&gt;data.json&lt;/code&gt; files, and four URLs still pointed at the old path (&lt;code&gt;/img/...&lt;/code&gt;). They had to become &lt;code&gt;/images/...&lt;/code&gt; — sidebar entries, friend links, all of it — then the site had to be rebuilt.&lt;/p&gt;

&lt;p&gt;Do the migration as a checklist, not a find-and-replace hope:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Find all old image URL prefixes in your content/data (&lt;code&gt;grep -rn "/img/"&lt;/code&gt; is your friend)&lt;/li&gt;
&lt;li&gt;[ ] Update them to the new path and rebuild&lt;/li&gt;
&lt;li&gt;[ ] Verify with &lt;code&gt;curl -I https://img.yourdomain.com/images/...&lt;/code&gt; — expect &lt;code&gt;200&lt;/code&gt; and the cache headers&lt;/li&gt;
&lt;li&gt;[ ] Check one page in the browser console to confirm zero &lt;code&gt;ERR_CONNECTION_RESET&lt;/code&gt; errors&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bandwidth: the honest constraint
&lt;/h2&gt;

&lt;p&gt;A low-spec mainland ECS — the kind that costs almost nothing — has a &lt;strong&gt;1 Mbps uplink, roughly 128 KB/s&lt;/strong&gt;. Static images barely touch the CPU, but bandwidth is a hard ceiling: a single 500 KB image takes about 4 seconds to transfer from the origin.&lt;/p&gt;

&lt;p&gt;This is why the setup is a &lt;em&gt;system&lt;/em&gt;, not a single decision:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compress at build time.&lt;/strong&gt; WebP images at 100–200 KB each change the whole math.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Long browser caching&lt;/strong&gt; (the 7-day header above) so repeat visits cost nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy loading&lt;/strong&gt; so off-screen images aren't fetched at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the volume in control&lt;/strong&gt; — the image set is reviewed, not accumulated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloudflare edge caching&lt;/strong&gt; so overseas traffic rarely touches the origin at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Respect the bandwidth budget and the cheap server is fine; ignore it and no amount of Cloudflare will save you.&lt;/p&gt;




&lt;h2&gt;
  
  
  The checklist I wish I'd had
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Image repo is private, &lt;code&gt;.gitignore&lt;/code&gt; verified with &lt;code&gt;git status&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] Nginx: only &lt;code&gt;/images/&lt;/code&gt; public; hidden files and repo root denied&lt;/li&gt;
&lt;li&gt;[ ] 80 → 443 redirect; security headers on&lt;/li&gt;
&lt;li&gt;[ ] Cloudflare: &lt;code&gt;img&lt;/code&gt; record added and &lt;strong&gt;proxied&lt;/strong&gt;; global SSL mode untouched&lt;/li&gt;
&lt;li&gt;[ ] certbot DNS-01 certificate issued and auto-renewing&lt;/li&gt;
&lt;li&gt;[ ] All old &lt;code&gt;/img/&lt;/code&gt; URLs cut over to &lt;code&gt;/images/&lt;/code&gt; and rebuilt&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;curl -I&lt;/code&gt; returns 200 with cache headers; console has no blocked-image errors&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The bottom line
&lt;/h2&gt;

&lt;p&gt;Self-hosted image hosting doesn't have to mean "server chugging under a global load." The stack here is a private GitHub repo for source control, a mainland cloud server as origin, Nginx serving exactly one public directory, and Cloudflare proxying DNS for the rest of the world — with certbot handling HTTPS. Total recurring cost is essentially the cheapest server tier you can rent.&lt;/p&gt;

&lt;p&gt;The real lesson is architectural: &lt;strong&gt;choose your origin for your dominant audience, then use CDN and DNS to serve everyone else.&lt;/strong&gt; My dominant audience is in mainland China, so images live on a mainland server; Cloudflare gives the overseas half an edge cache and never lets global traffic touch the 1 Mbps uplink. When the audience mix changes, the fix is one DNS toggle — not a migration.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article documents the real image hosting architecture behind &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt; — a GitHub private repo, a mainland cloud server, and Cloudflare DNS proxying. If you're weighing the same trade-offs, I'm happy to answer questions.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>nginx</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How I Built a Static Blog with 50+ Articles and Zero Frameworks: Pure HTML, CSS, and JavaScript</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 02:20:51 +0000</pubDate>
      <link>https://dev.to/whjin/how-i-built-a-static-blog-with-50-articles-and-zero-frameworks-pure-html-css-and-javascript-5708</link>
      <guid>https://dev.to/whjin/how-i-built-a-static-blog-with-50-articles-and-zero-frameworks-pure-html-css-and-javascript-5708</guid>
      <description>&lt;h1&gt;
  
  
  How I Built a Static Blog with 50+ Articles and Zero Frameworks: Pure HTML, CSS, and JavaScript
&lt;/h1&gt;

&lt;p&gt;Every few months, someone asks me the same question: "What framework is your blog built with? Next.js? Astro?" The answer usually surprises them: none. My blog, &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;, is a fully static site built with pure HTML, CSS, and vanilla JavaScript — no React, no Vue, no build framework. It has over 50 published articles, and it has held near-perfect PageSpeed scores for over a year.&lt;/p&gt;

&lt;p&gt;This is the story of why I went framework-free, how the architecture actually works, and the specific trade-offs you should consider before doing the same.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I Dropped Frameworks for a Content Site
&lt;/h2&gt;

&lt;p&gt;Frameworks solve real problems: state management, component re-rendering, routing, and code organization at scale. A blog doesn't have any of those problems. It has one job — serve text and images to readers as fast as possible.&lt;/p&gt;

&lt;p&gt;Once I framed it that way, the case for a zero-framework blog became obvious:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Speed is the feature.&lt;/strong&gt; No bundle to download, no hydration to wait for, no runtime JavaScript between the user and the content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintenance is nearly zero.&lt;/strong&gt; No dependency tree to keep updated, no breaking upgrades every six months, no lockfile churn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Total control.&lt;/strong&gt; Every byte of HTML is mine. I decide how it's structured, how it's cached, and how it's crawled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Longevity.&lt;/strong&gt; A plain HTML file from 2005 still renders today. I want this blog to outlive whatever the frontend ecosystem does next.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The catch: you lose the scaffolding that frameworks give you. So I built a small, custom toolchain to replace only the parts I actually needed.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Architecture: Content in Markdown, Pages in HTML
&lt;/h2&gt;

&lt;p&gt;The entire site follows one simple rule: &lt;strong&gt;write in Markdown, ship as static HTML.&lt;/strong&gt; No content is rendered on the client — every article is prerendered into its own standalone HTML file at build time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wuhuajin.github.io/
├── src/
│   ├── components/        # Reusable UI pieces (navigation, footer, sidebar, feed...)
│   ├── template/
│   │   └── posts/         # Article Markdown, organized by category (20+ categories)
│   ├── css/               # Third-party CSS (highlight.js themes, etc.)
│   └── js/                # Third-party JS (marked, highlight.js, APlayer)
├── scripts/               # Custom Node.js build scripts
├── server.js              # Local dev server (port 8000)
├── index.html
└── package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;src/&lt;/code&gt; directory is the source of truth. Each UI piece is a self-contained component — its own HTML fragment, CSS, and JavaScript. Nothing is shared through a bundler's module graph; components are simply assembled into pages by the build scripts.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Content Pipeline: Markdown → Prerendered HTML
&lt;/h2&gt;

&lt;p&gt;The heart of the system is the prerendering pipeline. Every article lives as Markdown with YAML front matter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;My&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Article"&lt;/span&gt;
&lt;span class="na"&gt;date&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2026-01-01&lt;/span&gt;
&lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;JavaScript"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;es6"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;async"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hand-written&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;meta&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;description&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;(never&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;auto-overwritten)"&lt;/span&gt;
&lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A custom Node.js script parses the front matter, renders the Markdown with &lt;code&gt;marked&lt;/code&gt;, applies syntax highlighting with &lt;code&gt;highlight.js&lt;/code&gt;, and writes out a complete standalone HTML page — including the table of contents, code-block toolbar, and reward card. The result is a page that renders perfectly even with JavaScript fully disabled.&lt;/p&gt;

&lt;p&gt;Why prerender instead of rendering client-side?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Crawlers see the full content.&lt;/strong&gt; Googlebot gets the complete article in the initial HTML. There's no "render the page before indexing it" dependency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instant first paint.&lt;/strong&gt; The browser has nothing to do but paint what's already there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resilience.&lt;/strong&gt; If a CDN edge or a third-party script fails, the content is still on the page.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  The Build System: Custom Node.js Scripts, No Bundler
&lt;/h2&gt;

&lt;p&gt;Instead of Webpack, Vite, or esbuild, the build is a sequence of small, focused &lt;code&gt;.cjs&lt;/code&gt; scripts:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Script&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;build-articles.cjs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Prerender every Markdown article into &lt;code&gt;posts/&amp;lt;category&amp;gt;/html/&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;build-feed.cjs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Parse front matter → generate the homepage feed &lt;code&gt;data.json&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;build-home.cjs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Generate homepage data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;build-sitemap.cjs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Auto-generate &lt;code&gt;sitemap.xml&lt;/code&gt; from the feed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;build-links.cjs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Build aggregation and resource-navigation pages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;add-front-matter.cjs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Backfill missing front matter fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;update-wordcount.js&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Count real words per article for the feed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;watch.cjs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;File watcher + live reload for development&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each script is &lt;strong&gt;idempotent&lt;/strong&gt; — running it twice produces no diff. That property alone has saved me hours of debugging. And because there's no bundler graph, a broken component fails loudly in the build output instead of as a subtle runtime error in the browser.&lt;/p&gt;

&lt;p&gt;For development, a small &lt;code&gt;server.js&lt;/code&gt; uses Node's native &lt;code&gt;http&lt;/code&gt; module, &lt;code&gt;chokidar&lt;/code&gt; for file watching, and a WebSocket connection for live reload. One command (&lt;code&gt;npm run dev&lt;/code&gt;) builds once, starts the server at &lt;code&gt;localhost:8000&lt;/code&gt;, and hot-reloads on change. No Vite, no webpack-dev-server, no 200MB &lt;code&gt;node_modules&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bilingual Without an i18n Library
&lt;/h2&gt;

&lt;p&gt;The site is English-first with a one-click Chinese switch. Instead of a heavyweight i18n framework, it uses a lightweight dictionary: a plain JavaScript object mapping English keys to translated strings, plus a runtime function that swaps text nodes and &lt;code&gt;lang&lt;/code&gt; attributes when the user switches.&lt;/p&gt;

&lt;p&gt;The whole i18n layer is one component (&lt;code&gt;src/components/i18n/&lt;/code&gt;) and a few hundred lines. It covers everything a blog actually needs — navigation, footer, buttons, and labels — without the 40KB+ payload of a full i18n solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Performance Numbers
&lt;/h2&gt;

&lt;p&gt;Zero framework doesn't automatically mean fast — you still have to do the work. Here are the results after 20+ rounds of optimization:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;Improvement&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Homepage HTML size&lt;/td&gt;
&lt;td&gt;57 KB&lt;/td&gt;
&lt;td&gt;34 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;−40%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Social share image&lt;/td&gt;
&lt;td&gt;576 KB&lt;/td&gt;
&lt;td&gt;262 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;−55%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CLS (layout shift)&lt;/td&gt;
&lt;td&gt;0.37&lt;/td&gt;
&lt;td&gt;&amp;lt; 0.1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;−73%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Render-blocking CSS&lt;/td&gt;
&lt;td&gt;11 KB&lt;/td&gt;
&lt;td&gt;Async loaded&lt;/td&gt;
&lt;td&gt;Eliminated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Render-blocking JS&lt;/td&gt;
&lt;td&gt;13 files&lt;/td&gt;
&lt;td&gt;All &lt;code&gt;defer&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Eliminated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The techniques are mostly boring and reliable: &lt;code&gt;defer&lt;/code&gt; on every script, &lt;code&gt;preconnect&lt;/code&gt; to the five third-party origins the site talks to, explicit &lt;code&gt;width&lt;/code&gt;/&lt;code&gt;height&lt;/code&gt; on every image, &lt;code&gt;aspect-ratio&lt;/code&gt; locked on cover containers, lazy loading below the fold, and non-critical CSS loaded asynchronously. The biggest single win was prerendering — because the HTML already contains everything, there's almost nothing left to block rendering.&lt;/p&gt;




&lt;h2&gt;
  
  
  When a Zero-Framework Blog Makes Sense (and When It Doesn't)
&lt;/h2&gt;

&lt;p&gt;Do this if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your site is &lt;strong&gt;content-first&lt;/strong&gt; — articles, documentation, product pages.&lt;/li&gt;
&lt;li&gt;You're comfortable maintaining a few hundred lines of build scripts.&lt;/li&gt;
&lt;li&gt;You want &lt;strong&gt;maximum performance&lt;/strong&gt; with a tiny attack surface.&lt;/li&gt;
&lt;li&gt;You plan to run the site for &lt;strong&gt;years&lt;/strong&gt;, not months.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don't do this if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need &lt;strong&gt;complex interactivity&lt;/strong&gt; — dashboards, real-time collaboration, or app-like behavior. That's what frameworks are for.&lt;/li&gt;
&lt;li&gt;You want a &lt;strong&gt;large team&lt;/strong&gt; contributing without learning your custom conventions.&lt;/li&gt;
&lt;li&gt;You value &lt;strong&gt;ecosystem leverage&lt;/strong&gt; — prebuilt components, plugins, and hiring familiarity — over raw control.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There's no shame in using a framework. The point is to choose based on what your site actually needs, not on what's popular.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I'd Do Differently
&lt;/h2&gt;

&lt;p&gt;Two things, looking back. First, I'd write the build scripts with better error messages from day one — "fail loudly" beats "fail mysteriously" every time. Second, I'd add automated checks earlier: a simple script that verifies every article has a meta description and every image has dimensions before deploy. Both would have saved me real debugging time.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article is based on the real-world architecture of &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;, a zero-framework static blog with 50+ articles running on GitHub Pages and Cloudflare CDN. If you're weighing framework-free options for your own content site, feel free to reach out.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>How I Monetize a Static Blog Without a Backend: AdSense, Membership, and Tips</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 02:20:15 +0000</pubDate>
      <link>https://dev.to/whjin/how-i-monetize-a-static-blog-without-a-backend-adsense-membership-and-tips-90j</link>
      <guid>https://dev.to/whjin/how-i-monetize-a-static-blog-without-a-backend-adsense-membership-and-tips-90j</guid>
      <description>&lt;h1&gt;
  
  
  How I Monetize a Static Blog Without a Backend: AdSense, Membership, and Tips
&lt;/h1&gt;

&lt;p&gt;"Static sites can't make money" is one of those assumptions developers repeat until they actually try. My blog, &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;, is a fully static site — pure HTML, CSS, and JavaScript on GitHub Pages — and it generates income through three streams: display ads, a membership subscription, and reader tips. No backend, no database, no payment server of my own.&lt;/p&gt;

&lt;p&gt;This article breaks down how each revenue stream works on a static site, what I learned setting them up, and the compliance details that are easy to skip.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Three Revenue Streams
&lt;/h2&gt;

&lt;p&gt;I deliberately avoided putting everything in one basket:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Display ads&lt;/strong&gt; (Google AdSense) — passive, scales with traffic&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Membership subscription&lt;/strong&gt; (Waffo Pancake) — recurring, predictable&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reader tips&lt;/strong&gt; (WeChat / Alipay QR) — frictionless, personal&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each one has a different effort-to-revenue profile. Ads are passive but low-yield per visitor. Membership is the highest-value stream but requires a compelling offer. Tips are unpredictable but create a direct reader relationship.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Display Ads: AdSense on a Static Site
&lt;/h2&gt;

&lt;p&gt;AdSense is the easiest stream to start. On a static site it's genuinely plug-and-play: you paste the ad script once, and Google handles everything else.&lt;/p&gt;

&lt;p&gt;Two things made a real difference for me:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Placement control.&lt;/strong&gt; Ad units in my sidebar and between feed cards are managed through a &lt;code&gt;data.json&lt;/code&gt; file. Each ad card has a &lt;code&gt;sort&lt;/code&gt; field — lower numbers mean higher priority. When I want to test a new position, I change a number, rebuild, and deploy. No ad-management dashboard gymnastics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance discipline.&lt;/strong&gt; Ads are the enemy of Core Web Vitals if you let them be. I keep them lazy-loaded, fixed in dimensions, and out of the above-the-fold critical path. My CLS stayed under 0.1 with ads active — it's possible, but only if you treat every ad slot as a potential layout shift and force it to reserve its space.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Membership: Subscriptions Without a Backend
&lt;/h2&gt;

&lt;p&gt;The subscription stream is the interesting one. A static site can't run a payment server — so I use a third-party subscription service (Waffo Pancake) that hosts the checkout and payment logic.&lt;/p&gt;

&lt;p&gt;Here's what the setup looks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pricing&lt;/strong&gt;: $9.99/month with a 7-day free trial&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Checkout&lt;/strong&gt;: hosted by the subscription provider, embedded on a dedicated reward page&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delivery&lt;/strong&gt;: membership status is handled by the provider; the static site only needs to show/hide member content based on what it returns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benefits of not running my own billing backend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No PCI compliance burden on my side&lt;/li&gt;
&lt;li&gt;No server to keep patched for payment handling&lt;/li&gt;
&lt;li&gt;Recurring billing, dunning, and receipts are handled externally&lt;/li&gt;
&lt;li&gt;I can focus on content and product value instead of payment infrastructure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trade-off is a revenue share and less control over the checkout experience. For an indie site my size, that's an easy trade to make.&lt;/p&gt;

&lt;p&gt;I also built a dedicated product landing page (&lt;code&gt;/product.html&lt;/code&gt;) that presents the membership as part of a broader "Developer Tools Suite" — a standalone page for the offer, separate from the blog content. A dedicated offer page converts better than a paragraph buried in a blog post.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Tips: The Human Touch
&lt;/h2&gt;

&lt;p&gt;The third stream is reader tips via WeChat and Alipay QR codes. On the surface it's just two images on a reward page — but the real trick is &lt;em&gt;where&lt;/em&gt; you put the ask.&lt;/p&gt;

&lt;p&gt;I embed a small reward card inside every article (a design I adapted from &lt;a href="https://zhheo.com" rel="noopener noreferrer"&gt;zhheo.com&lt;/a&gt; with permission). It appears only after the reader has consumed the content, at the point where they've already gotten value. The conversion rate on in-article asks is meaningfully higher than a footer link.&lt;/p&gt;

&lt;p&gt;Tips won't replace a salary. But they do something ads and subscriptions can't: they tell you, directly, which articles readers found valuable enough to pay for. That's product signal disguised as income.&lt;/p&gt;




&lt;h2&gt;
  
  
  Compliance: The Part Everyone Forgets
&lt;/h2&gt;

&lt;p&gt;Monetization on a static site still carries obligations, and skipping them gets expensive later. On my site:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Refund and liability terms&lt;/strong&gt; are published (dedicated terms page with refund policy and liability clauses)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An AIGC content usage policy&lt;/strong&gt; explains how AI-assisted content is labeled and used&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GDPR considerations&lt;/strong&gt; are handled: cookie consent banner, Google Consent Mode v2, and a privacy policy — because AdSense and analytics drop cookies on EU visitors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these are sexy, and all of them matter. AdSense in particular requires compliance signals on the page; without them you risk account-level problems, not just lower revenue.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I'd Do Differently
&lt;/h2&gt;

&lt;p&gt;Three things, in hindsight:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start with the membership offer earlier.&lt;/strong&gt; Ads monetize traffic; membership monetizes trust. I built the subscription months after the blog had steady traffic, and I left revenue on the table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure per-article performance.&lt;/strong&gt; Don't just track pageviews — track which articles generate tips and trial signups. The content that converts is your real editorial signal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the compliance pages current.&lt;/strong&gt; Policies drift out of date as you add streams. Budget an annual review.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;A static site is not a revenue ceiling. Ads cover the baseline, a third-party subscription adds recurring income, and tips provide direct reader feedback — all without running a backend.&lt;/p&gt;

&lt;p&gt;The pattern generalizes beyond blogs: any content site with decent traffic can run the same three-stream structure. The hard part isn't the technology; it's the offer and the discipline to keep performance and compliance solid while you scale.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article shares the monetization setup of &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;, a static blog running AdSense, a Waffo Pancake membership, and reader tips without any backend infrastructure. Questions or feedback are always welcome.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Launching a Personal Website for a Global Audience: GitHub Pages, Cloudflare CDN, and DNS Strategy</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 02:20:09 +0000</pubDate>
      <link>https://dev.to/whjin/launching-a-personal-website-for-a-global-audience-github-pages-cloudflare-cdn-and-dns-strategy-17i7</link>
      <guid>https://dev.to/whjin/launching-a-personal-website-for-a-global-audience-github-pages-cloudflare-cdn-and-dns-strategy-17i7</guid>
      <description>&lt;h1&gt;
  
  
  Launching a Personal Website for a Global Audience: GitHub Pages, Cloudflare CDN, and DNS Strategy
&lt;/h1&gt;

&lt;p&gt;Most personal websites are built for the wrong audience. Not the wrong people — the wrong geography. If your site is served from a single origin in one region, visitors on other continents pay for it in latency, and Google notices.&lt;/p&gt;

&lt;p&gt;My site, &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;, gets visitors from North America, Europe, and Asia. Getting it to load fast everywhere took three coordinated decisions: hosting on GitHub Pages, putting Cloudflare in front of it, and running a dual DNS setup across two providers. This article walks through each layer and the exact pitfalls I hit along the way.&lt;/p&gt;




&lt;h2&gt;
  
  
  Layer 1: Hosting on GitHub Pages
&lt;/h2&gt;

&lt;p&gt;GitHub Pages is the most underrated free hosting tier for static sites. It gives you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Free HTTPS with automatic certificate renewal&lt;/li&gt;
&lt;li&gt;Unlimited bandwidth within fair-use limits&lt;/li&gt;
&lt;li&gt;A global CDN (Fastly) as the underlying edge&lt;/li&gt;
&lt;li&gt;Git-based deploys — pushing to &lt;code&gt;main&lt;/code&gt; is your deployment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a static site that builds locally (or in CI), it's genuinely production-grade. Two caveats cost me real debugging time:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The &lt;code&gt;.nojekyll&lt;/code&gt; file.&lt;/strong&gt; GitHub Pages runs Jekyll over your repository by default. Jekyll ignores files and folders that start with an underscore, and it silently mangles Markdown files without front matter. Until I added an empty &lt;code&gt;.nojekyll&lt;/code&gt; file at the repo root, some article pages 404'd mysteriously after every deploy. The fix is one file and it's non-negotiable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Path consistency.&lt;/strong&gt; If your build generates URLs with an &lt;code&gt;/html/&lt;/code&gt; segment, every internal link must use it consistently. A mismatch between the feed's URLs and the actual file layout produces intermittent 404s that are painful to chase. I solved it by making the build script the single source of truth for both feed data and file output.&lt;/p&gt;




&lt;h2&gt;
  
  
  Layer 2: Cloudflare CDN in Front
&lt;/h2&gt;

&lt;p&gt;GitHub Pages' edge is good, but I wanted more control: custom caching rules, analytics without third-party scripts, and protection for the custom domain. Cloudflare sits in front of the site and handles all of it.&lt;/p&gt;

&lt;p&gt;The setup is deliberately simple — a free Cloudflare plan with the DNS proxied (orange-cloud). The wins:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Caching&lt;/strong&gt;: static assets are served from Cloudflare's edge cache, reducing origin load to nearly zero&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TTL control&lt;/strong&gt;: long cache lifetimes for images and CSS, short ones for HTML so content updates propagate quickly&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analytics&lt;/strong&gt;: Cloudflare Web Analytics runs without cookies and without slowing the page — genuinely useful, privacy-friendly, and GDPR-compliant by default&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One lesson: when you change a build or add new pages, don't fight the cache. Configure a cache-busting strategy (versioned filenames or a purge step) instead of setting everything to no-cache and losing the whole benefit.&lt;/p&gt;




&lt;h2&gt;
  
  
  Layer 3: Dual DNS — Alibaba Cloud + Cloudflare
&lt;/h2&gt;

&lt;p&gt;This is the part people rarely write about: I run &lt;strong&gt;dual DNS resolution&lt;/strong&gt; across Alibaba Cloud and Cloudflare.&lt;/p&gt;

&lt;p&gt;Why two providers? Redundancy and control. If one DNS provider has an outage, the other still resolves the domain. For a site that monetizes via ads and subscriptions, a DNS failure is lost revenue, not just an inconvenience.&lt;/p&gt;

&lt;p&gt;The practical setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Alibaba Cloud&lt;/strong&gt; is the registrar and the primary DNS authority (my domain's home region)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloudflare&lt;/strong&gt; is configured as the CDN and handles proxied traffic for &lt;code&gt;www&lt;/code&gt; and the apex domain&lt;/li&gt;
&lt;li&gt;The two are coordinated so that DNS resolution and CDN proxying don't fight each other&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trade-off is operational complexity: you now have two dashboards to keep in sync, and a misconfiguration in either breaks resolution. It's only worth it once your site has real traffic — for a brand-new site, one competent DNS provider is the right call.&lt;/p&gt;




&lt;h2&gt;
  
  
  Analytics: Three Tools, Three Jobs
&lt;/h2&gt;

&lt;p&gt;I run three analytics tools, and each has a distinct job:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cloudflare Web Analytics&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Privacy-friendly pageview metrics, zero cookies, GDPR-safe by default&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Microsoft Clarity&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Session recordings and heatmaps — how visitors actually scroll and click&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Google Analytics 4&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Full funnel and demographic data, integrated with AdSense reporting&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three tools is more than most sites need, but the overlap is intentional: each answers a different question, and they cross-check each other. Clarity in particular has caught usability problems (dead clicks, rage clicks, layout confusion) that no number of pageview charts would ever reveal.&lt;/p&gt;

&lt;p&gt;For a privacy-sensitive touch, the site also runs a self-hosted visit counter at &lt;code&gt;stats.wuhuajin.com&lt;/code&gt; — a Cloudflare Worker with a D1 database that increments on each page load. It's a small detail, but it means the footer view counts don't depend on any third-party analytics being enabled.&lt;/p&gt;




&lt;h2&gt;
  
  
  Compliance: GDPR for a Global Audience
&lt;/h2&gt;

&lt;p&gt;If your visitors include the EU, compliance is part of the deployment, not an afterthought. My setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cookie consent banner&lt;/strong&gt; (GDPR/CCPA) — appears before any non-essential cookies load&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Consent Mode v2&lt;/strong&gt; — analytics and ads respect the visitor's consent choice at the platform level&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Privacy policy, terms, about, and contact pages&lt;/strong&gt; — the standard legal set, actually linked from the footer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No cross-site tracking cookies&lt;/strong&gt; beyond consented analytics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The practical effect: the site never drops a tracking cookie on a visitor who hasn't consented, and the consent state is respected by Google's ad and analytics stack. This isn't just legal hygiene — it's also a trust signal that shows up in how seriously readers and advertisers take the site.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Launch Checklist I Wish I'd Had
&lt;/h2&gt;

&lt;p&gt;Before you point your domain at a global audience, verify all of this in one pass:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Empty &lt;code&gt;.nojekyll&lt;/code&gt; at repo root (if using GitHub Pages)&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;robots.txt&lt;/code&gt; and auto-generated &lt;code&gt;sitemap.xml&lt;/code&gt; present and correct&lt;/li&gt;
&lt;li&gt;[ ] Custom 404 page with a real &lt;code&gt;h1&lt;/code&gt; and navigation&lt;/li&gt;
&lt;li&gt;[ ] HTTPS enforced end-to-end (origin + CDN + DNS)&lt;/li&gt;
&lt;li&gt;[ ] Cache-busting strategy for CSS/JS/assets&lt;/li&gt;
&lt;li&gt;[ ] Cookie consent + Consent Mode v2 wired up before any analytics/ads load&lt;/li&gt;
&lt;li&gt;[ ] Privacy policy and terms live and linked&lt;/li&gt;
&lt;li&gt;[ ] Analytics double-check: you can see traffic from at least two continents within a day of launching&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;A fast, compliant, global personal site is achievable with free or near-free infrastructure: GitHub Pages for hosting, Cloudflare for the CDN edge, dual DNS for resilience, and a consent-first analytics stack. None of it requires a server you manage yourself.&lt;/p&gt;

&lt;p&gt;The hidden cost is coordination — every layer interacts with the others, and the debugging time goes into the seams: &lt;code&gt;.nojekyll&lt;/code&gt;, path consistency, cache invalidation, DNS sync. Get those right once, and the whole stack runs for years with almost no maintenance.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article covers the real deployment architecture of &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt; — GitHub Pages, Cloudflare CDN, dual DNS, and a consent-first analytics stack. If you're launching a site for a global audience, I'm happy to answer questions.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Webpack Module Bundling Explained: How It Works Under the Hood</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 00:41:45 +0000</pubDate>
      <link>https://dev.to/whjin/webpack-module-bundling-explained-how-it-works-under-the-hood-162f</link>
      <guid>https://dev.to/whjin/webpack-module-bundling-explained-how-it-works-under-the-hood-162f</guid>
      <description>&lt;h1&gt;
  
  
  Webpack Module Bundling Explained: How It Works Under the Hood
&lt;/h1&gt;

&lt;p&gt;If you've ever built a frontend project in the last decade, you've probably used Webpack. It's the tool that turns your &lt;code&gt;import&lt;/code&gt; statements and separate files into a single (or multiple) optimized bundle that the browser can run.&lt;/p&gt;

&lt;p&gt;But have you ever wondered what actually happens when you run &lt;code&gt;webpack&lt;/code&gt;? How does it go from dozens of scattered &lt;code&gt;.js&lt;/code&gt; files to one &lt;code&gt;bundle.js&lt;/code&gt;? And why does it sometimes feel like magic?&lt;/p&gt;

&lt;p&gt;In this article, we'll peel back the curtain and explore how Webpack works internally. By the end, you'll understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What module bundling actually means&lt;/li&gt;
&lt;li&gt;How Webpack builds its dependency graph&lt;/li&gt;
&lt;li&gt;The difference between &lt;code&gt;Compiler&lt;/code&gt; and &lt;code&gt;Compilation&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;How modules are wrapped and executed in the browser&lt;/li&gt;
&lt;li&gt;Why code splitting works the way it does&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's dive in.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem: Browser-Native Modules Are Not Enough
&lt;/h2&gt;

&lt;p&gt;Before module bundlers like Webpack, we had a fundamental problem: browsers don't natively support &lt;code&gt;import&lt;/code&gt;/&lt;code&gt;export&lt;/code&gt; the way Node.js does (well, they do now with ES modules, but there are still caveats).&lt;/p&gt;

&lt;p&gt;In the early days, we'd load multiple &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"utils.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This worked, but it had serious issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Global scope pollution&lt;/strong&gt;: Everything in &lt;code&gt;utils.js&lt;/code&gt; leaked into the global namespace&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order matters&lt;/strong&gt;: You had to load dependencies before dependents&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No dependency management&lt;/strong&gt;: No automatic way to know what depends on what&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then came ES modules (&lt;code&gt;import&lt;/code&gt;/&lt;code&gt;export&lt;/code&gt;), which solved the syntax problem. But we still need bundling for other reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tree shaking (removing unused code)&lt;/li&gt;
&lt;li&gt;Code splitting (loading only what's needed)&lt;/li&gt;
&lt;li&gt;Asset processing (TypeScript, SCSS, images)&lt;/li&gt;
&lt;li&gt;Performance (fewer requests, smaller files)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where Webpack comes in.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Concepts You Need to Know
&lt;/h2&gt;

&lt;p&gt;Before we walk through the build process, let's define the key players:&lt;/p&gt;

&lt;h3&gt;
  
  
  Entry
&lt;/h3&gt;

&lt;p&gt;The entry point is where Webpack starts building its dependency graph. It's the "root" module that everything else hangs off of.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// webpack.config.js&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Webpack starts here and follows every &lt;code&gt;import&lt;/code&gt; statement to discover all the files your app needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;The output tells Webpack where to put the bundled files and what to name them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Loaders
&lt;/h3&gt;

&lt;p&gt;Loaders teach Webpack how to process non-JavaScript files. By default, Webpack only understands JavaScript. But what about CSS? TypeScript? Images?&lt;/p&gt;

&lt;p&gt;That's what loaders are for. They transform files before they're added to the bundle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;css$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;ts$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ts-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Plugins
&lt;/h3&gt;

&lt;p&gt;Plugins are more powerful than loaders. They can hook into the entire build lifecycle and do things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract CSS into separate files&lt;/li&gt;
&lt;li&gt;Optimize assets&lt;/li&gt;
&lt;li&gt;Generate HTML files&lt;/li&gt;
&lt;li&gt;Define environment variables
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HtmlWebpackPlugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;html-webpack-plugin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HtmlWebpackPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/index.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Build Process: Three Stages
&lt;/h2&gt;

&lt;p&gt;Now that we know the core concepts, let's walk through what happens when you run &lt;code&gt;webpack&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The build happens in three main stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Initialization&lt;/strong&gt;: Read configuration, set up plugins and loaders&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compilation&lt;/strong&gt;: Build the dependency graph, process modules, generate assets&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Emission&lt;/strong&gt;: Write the final files to disk&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's look at each stage in detail.&lt;/p&gt;




&lt;h3&gt;
  
  
  Stage 1: Initialization
&lt;/h3&gt;

&lt;p&gt;When you run &lt;code&gt;webpack&lt;/code&gt;, the first thing it does is create a &lt;code&gt;Compiler&lt;/code&gt; instance.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Compiler&lt;/code&gt; is the overall manager. It:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reads your configuration file&lt;/li&gt;
&lt;li&gt;Registers all plugins&lt;/li&gt;
&lt;li&gt;Sets up the file system&lt;/li&gt;
&lt;li&gt;Runs the initial build
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;webpack&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;compiler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// compiler.run() starts the build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Compiler&lt;/code&gt; lives for the entire lifetime of your Webpack process. If you're using &lt;code&gt;webpack-dev-server&lt;/code&gt;, the &lt;code&gt;Compiler&lt;/code&gt; is created once and reused across rebuilds.&lt;/p&gt;




&lt;h3&gt;
  
  
  Stage 2: Compilation
&lt;/h3&gt;

&lt;p&gt;This is where the real work happens. Each time Webpack builds (or rebuilds), it creates a new &lt;code&gt;Compilation&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Compilation&lt;/code&gt; represents one single build. It tracks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All the modules being processed&lt;/li&gt;
&lt;li&gt;All the generated assets&lt;/li&gt;
&lt;li&gt;The dependency graph&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's what happens during compilation:&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2.1: Build the Dependency Graph
&lt;/h4&gt;

&lt;p&gt;Webpack starts at the entry point and recursively finds every imported module.&lt;/p&gt;

&lt;p&gt;For example, if your entry file looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// index.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./utils.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;World&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Webpack will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read &lt;code&gt;index.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;See that it imports &lt;code&gt;./utils.js&lt;/code&gt; → add that to the graph&lt;/li&gt;
&lt;li&gt;See that it imports &lt;code&gt;./styles.css&lt;/code&gt; → add that to the graph&lt;/li&gt;
&lt;li&gt;Process &lt;code&gt;utils.js&lt;/code&gt; → find its imports&lt;/li&gt;
&lt;li&gt;Process &lt;code&gt;styles.css&lt;/code&gt; → run it through loaders&lt;/li&gt;
&lt;li&gt;Repeat until everything is discovered&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This creates a &lt;strong&gt;dependency graph&lt;/strong&gt;: a tree (or more accurately, a DAG) of all the modules your app needs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2.2: Resolve Modules
&lt;/h4&gt;

&lt;p&gt;When Webpack sees &lt;code&gt;import { greet } from './utils.js'&lt;/code&gt;, it needs to figure out what file &lt;code&gt;./utils.js&lt;/code&gt; actually refers to.&lt;/p&gt;

&lt;p&gt;This is called &lt;strong&gt;resolution&lt;/strong&gt;. Webpack's resolver:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Checks if it's a relative path (starts with &lt;code&gt;./&lt;/code&gt; or &lt;code&gt;../&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Tries adding extensions (&lt;code&gt;.js&lt;/code&gt;, &lt;code&gt;.jsx&lt;/code&gt;, &lt;code&gt;.ts&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;li&gt;Checks if it's a directory (then looks for &lt;code&gt;index.js&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Resolves aliases from your config&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 2.3: Process Modules with Loaders
&lt;/h4&gt;

&lt;p&gt;Once Webpack has found a file, it runs it through any matching loaders.&lt;/p&gt;

&lt;p&gt;For example, for a &lt;code&gt;.css&lt;/code&gt; file:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;css-loader&lt;/code&gt; reads the CSS file and resolves &lt;code&gt;@import&lt;/code&gt; and &lt;code&gt;url()&lt;/code&gt; statements&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;style-loader&lt;/code&gt; takes the processed CSS and injects it into the DOM via &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tags&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For TypeScript:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;ts-loader&lt;/code&gt; (or &lt;code&gt;babel-loader&lt;/code&gt; with TypeScript preset) transpiles &lt;code&gt;.ts&lt;/code&gt; to &lt;code&gt;.js&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The output of loader processing is always JavaScript. That's the contract: loaders take any file type, output JavaScript.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2.4: Parse to AST
&lt;/h4&gt;

&lt;p&gt;After loaders process a module, Webpack parses the resulting JavaScript into an &lt;strong&gt;Abstract Syntax Tree (AST)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The AST is a structured representation of your code. Webpack uses it to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find all &lt;code&gt;import&lt;/code&gt; statements (to discover more dependencies)&lt;/li&gt;
&lt;li&gt;Apply transformations (like removing unused exports for tree shaking)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is how Webpack knows what other modules a file depends on.&lt;/p&gt;




&lt;h3&gt;
  
  
  Stage 3: Emission
&lt;/h3&gt;

&lt;p&gt;Once all modules are processed and the dependency graph is complete, Webpack generates the final bundle.&lt;/p&gt;

&lt;p&gt;But wait — how does it turn a graph of modules into a single runnable file?&lt;/p&gt;




&lt;h2&gt;
  
  
  How Modules Actually Run in the Browser
&lt;/h2&gt;

&lt;p&gt;This is the part most people don't think about. Let's look at what's actually inside a Webpack bundle.&lt;/p&gt;

&lt;p&gt;Remember: browsers don't natively have a &lt;code&gt;require&lt;/code&gt; function (not the old way, anyway). So Webpack has to simulate one.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Module Wrapper
&lt;/h3&gt;

&lt;p&gt;Every module in your bundle gets wrapped in a function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your actual module code goes here&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Webpack stores all these wrapped modules in an object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;modules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/utils.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/styles.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The &lt;code&gt;require&lt;/code&gt; Function
&lt;/h3&gt;

&lt;p&gt;Then Webpack defines its own &lt;code&gt;require&lt;/code&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;moduleId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Check if we've already loaded this module&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;installedModules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;moduleId&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;installedModules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;moduleId&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Create a new module object&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;installedModules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;moduleId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
    &lt;span class="na"&gt;loaded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="c1"&gt;// Run the module function&lt;/span&gt;
  &lt;span class="nx"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;moduleId&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;require&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Mark it as loaded&lt;/span&gt;
  &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loaded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Putting It All Together
&lt;/h3&gt;

&lt;p&gt;The bundle ends up looking like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// The require function we just defined&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;moduleId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Start with the entry point&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})({&lt;/span&gt;
  &lt;span class="c1"&gt;// All our modules&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/utils.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;World&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/utils.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! That's how Webpack bundles work. It's just a big IIFE (Immediately Invoked Function Expression) that defines a custom &lt;code&gt;require&lt;/code&gt; and starts executing from your entry point.&lt;/p&gt;




&lt;h2&gt;
  
  
  Code Splitting: Why and How
&lt;/h2&gt;

&lt;p&gt;One of Webpack's most powerful features is code splitting — splitting your code into multiple bundles that load on demand.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Code Split?
&lt;/h3&gt;

&lt;p&gt;Imagine your app has 10 different pages. If you bundle everything into one file, users have to download all 10 pages' code just to see the homepage. That's wasteful.&lt;/p&gt;

&lt;p&gt;Code splitting lets you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load the homepage code first&lt;/li&gt;
&lt;li&gt;Load other pages only when the user navigates to them&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How It Works: Dynamic Imports
&lt;/h3&gt;

&lt;p&gt;Webpack supports dynamic imports using the &lt;code&gt;import()&lt;/code&gt; syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Instead of:&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;aboutPage&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./about.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Do:&lt;/span&gt;
&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./about.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aboutPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When Webpack sees &lt;code&gt;import()&lt;/code&gt;, it automatically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Splits that module into a separate chunk&lt;/li&gt;
&lt;li&gt;Generates a small JSONP loader that fetches the chunk on demand&lt;/li&gt;
&lt;li&gt;Returns a Promise that resolves when the chunk is loaded&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Runtime Chunk
&lt;/h3&gt;

&lt;p&gt;Code splitting introduces another concept: the &lt;strong&gt;runtime chunk&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The runtime is a small piece of Webpack boilerplate that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manages module loading&lt;/li&gt;
&lt;li&gt;Tracks which chunks have been loaded&lt;/li&gt;
&lt;li&gt;Resolves dependencies between chunks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's usually just a few KB, but it's essential for code splitting to work.&lt;/p&gt;




&lt;h2&gt;
  
  
  Production Optimization
&lt;/h2&gt;

&lt;p&gt;In production mode, Webpack applies a bunch of optimizations automatically:&lt;/p&gt;

&lt;h3&gt;
  
  
  Tree Shaking
&lt;/h3&gt;

&lt;p&gt;Tree shaking removes unused exports from your bundle.&lt;/p&gt;

&lt;p&gt;If you have a file like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// utils.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;usedFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am used&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unusedFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am not used&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you only import &lt;code&gt;usedFunction&lt;/code&gt;, Webpack will completely remove &lt;code&gt;unusedFunction&lt;/code&gt; from the final bundle.&lt;/p&gt;

&lt;p&gt;This works because ES modules have a static structure — you can't dynamically add exports at runtime. CommonJS (&lt;code&gt;require()&lt;/code&gt;) doesn't support tree shaking as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Minification
&lt;/h3&gt;

&lt;p&gt;Webpack uses Terser (or another minifier) to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove whitespace and comments&lt;/li&gt;
&lt;li&gt;Shorten variable names&lt;/li&gt;
&lt;li&gt;Remove dead code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can reduce bundle size by 50% or more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Module Concatenation
&lt;/h3&gt;

&lt;p&gt;By default, each module is wrapped in its own function scope. Module concatenation (also called "scope hoisting") merges all modules into a single scope, which:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces function wrapper overhead&lt;/li&gt;
&lt;li&gt;Makes the bundle smaller and faster&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common Pitfalls and How to Avoid Them
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Oversized Bundles
&lt;/h3&gt;

&lt;p&gt;If your bundle is hundreds of KB, you're probably not code splitting enough.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Use route-based code splitting — split by page/route.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Slow Build Times
&lt;/h3&gt;

&lt;p&gt;As your project grows, Webpack builds can get slow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solutions&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;thread-loader&lt;/code&gt; to parallelize loading&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;babel-loader&lt;/code&gt; cache&lt;/li&gt;
&lt;li&gt;Exclude &lt;code&gt;node_modules&lt;/code&gt; from unnecessary loaders&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;development&lt;/code&gt; mode for local development (faster builds)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Duplicated Dependencies
&lt;/h3&gt;

&lt;p&gt;If you have multiple chunks that all import Lodash, Lodash gets bundled into each chunk.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Use the &lt;code&gt;SplitChunksPlugin&lt;/code&gt; to extract shared dependencies into a common chunk.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;optimization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;splitChunks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Webpack can feel like magic, but it's actually a pretty straightforward pipeline:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start at the entry point&lt;/strong&gt; and recursively discover all dependencies&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Process each module&lt;/strong&gt; through loaders to convert it to JavaScript&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parse to AST&lt;/strong&gt; to find more dependencies&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wrap every module&lt;/strong&gt; in a function with a custom &lt;code&gt;require&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle everything&lt;/strong&gt; into one or more files&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimize for production&lt;/strong&gt; with tree shaking and minification&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you understand this pipeline, debugging Webpack issues becomes much easier. You'll know exactly where to look when something goes wrong.&lt;/p&gt;

&lt;p&gt;The frontend ecosystem has been moving away from Webpack toward faster tools like Vite and esbuild. But understanding how Webpack works still gives you a solid foundation for understanding all module bundlers — the core concepts are the same.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article was originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;Wu Huajin's blog&lt;/a&gt;, where I write about frontend engineering, performance optimization, and developer tools.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>performance</category>
      <category>bundler</category>
    </item>
    <item>
      <title>Static Site Performance Optimization Checklist (2026)</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 00:40:59 +0000</pubDate>
      <link>https://dev.to/whjin/static-site-performance-optimization-checklist-2026-f32</link>
      <guid>https://dev.to/whjin/static-site-performance-optimization-checklist-2026-f32</guid>
      <description>&lt;h1&gt;
  
  
  Static Site Performance Optimization Checklist (2026)
&lt;/h1&gt;

&lt;p&gt;Static sites are supposed to be fast. That's the whole point of using something like Jekyll, Hugo, or Astro — no server-side rendering, no database queries, just pure HTML.&lt;/p&gt;

&lt;p&gt;But "static" doesn't automatically mean "fast." I've seen static sites that score worse on PageSpeed Insights than some heavily dynamic WordPress sites.&lt;/p&gt;

&lt;p&gt;After optimizing my own blog (deployed on GitHub Pages), I've compiled this checklist of performance optimizations that actually move the needle. These are the things that matter — not the micro-optimizations that save you 20ms.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Big Picture
&lt;/h2&gt;

&lt;p&gt;Before we dive into the checklist, let's remember what we're optimizing for. Google's Core Web Vitals are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LCP (Largest Contentful Paint)&lt;/strong&gt;: How long until the biggest content element renders&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FID (First Input Delay)&lt;/strong&gt;: How responsive the page is when you first interact with it (now replaced by INP)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CLS (Cumulative Layout Shift)&lt;/strong&gt;: How much the layout shifts unexpectedly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These three metrics are what Google cares about most. Everything else is secondary.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Image Optimization
&lt;/h2&gt;

&lt;p&gt;Images are usually the heaviest part of any page. If you fix nothing else, fix your images.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compress images&lt;/strong&gt;: Use tools like &lt;code&gt;squoosh&lt;/code&gt; or &lt;code&gt;sharp&lt;/code&gt; to reduce file size. You can often cut image size by 50-70% without noticeable quality loss.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use modern formats&lt;/strong&gt;: WebP or AVIF are 25-50% smaller than JPEG/PNG. Just make sure you provide fallbacks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy load below-the-fold images&lt;/strong&gt;: Add &lt;code&gt;loading="lazy"&lt;/code&gt; to images that aren't in the initial viewport. The browser will load them only when the user scrolls near them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; attributes&lt;/strong&gt;: This prevents layout shifts (CLS). The browser can reserve the right amount of space before the image loads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prioritize above-the-fold images&lt;/strong&gt;: Add &lt;code&gt;fetchpriority="high"&lt;/code&gt; to your LCP image (usually the logo or hero image).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Don't Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Don't serve 2000px wide images when they'll only display at 400px wide&lt;/li&gt;
&lt;li&gt;Don't use unoptimized PNGs for photos (use JPEG or WebP instead)&lt;/li&gt;
&lt;li&gt;Don't forget to set dimensions (this is the #1 cause of CLS)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. CSS Optimization
&lt;/h2&gt;

&lt;p&gt;Render-blocking CSS is one of the biggest culprits for slow FCP. The browser can't render the page until it has downloaded and parsed all CSS.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inline critical CSS&lt;/strong&gt;: The CSS needed for above-the-fold content should be inlined directly in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;. The rest can be loaded asynchronously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async load non-critical CSS&lt;/strong&gt;: Use &lt;code&gt;media="print" onload="this.media='all'"&lt;/code&gt; trick to load CSS without blocking rendering.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remove unused CSS&lt;/strong&gt;: Audit your stylesheets and remove anything you're not actually using. Tools like PurgeCSS can help.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minify CSS&lt;/strong&gt;: Remove whitespace, comments, and shorten variable names.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Async CSS Trick
&lt;/h3&gt;

&lt;p&gt;Here's the pattern I use for non-critical CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Load asynchronously (won't block rendering) --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"non-critical.css"&lt;/span&gt; &lt;span class="na"&gt;media=&lt;/span&gt;&lt;span class="s"&gt;"print"&lt;/span&gt; &lt;span class="na"&gt;onload=&lt;/span&gt;&lt;span class="s"&gt;"this.media='all'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Fallback for no-JS users --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;noscript&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"non-critical.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/noscript&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;media="print"&lt;/code&gt; trick makes the browser think this CSS is only for printing, so it loads it asynchronously. Then &lt;code&gt;onload&lt;/code&gt; switches it to &lt;code&gt;media="all"&lt;/code&gt; once it's loaded.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. JavaScript Optimization
&lt;/h2&gt;

&lt;p&gt;JavaScript is the most common cause of poor TBT (Total Blocking Time). The more JS you have, the longer the browser spends parsing and executing it, and the less responsive the page feels.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Defer non-critical JS&lt;/strong&gt;: Add &lt;code&gt;defer&lt;/code&gt; to scripts that don't need to run immediately. This tells the browser to download the script in the background and execute it after the HTML has finished parsing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code split&lt;/strong&gt;: Don't load all your JS at once. Split it by route or by feature, so users only download what they need.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tree shake&lt;/strong&gt;: Remove unused code. Modern bundlers (Webpack, Rollup, esbuild) do this automatically if you use ES modules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minify and compress&lt;/strong&gt;: Terser or esbuild can reduce JS size by 50% or more.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Defer vs Async: What's the Difference?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Execution Order&lt;/th&gt;
&lt;th&gt;DOMContentLoaded&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;defer&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Preserved (runs in order)&lt;/td&gt;
&lt;td&gt;Waits for deferred scripts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;async&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not preserved (runs as soon as it loads)&lt;/td&gt;
&lt;td&gt;Doesn't wait&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;None (sync)&lt;/td&gt;
&lt;td&gt;Preserved, blocks parsing&lt;/td&gt;
&lt;td&gt;Blocks everything&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Use &lt;code&gt;defer&lt;/code&gt; when your scripts depend on each other. Use &lt;code&gt;async&lt;/code&gt; for things like analytics that don't affect the page.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Network Optimization
&lt;/h2&gt;

&lt;p&gt;Even if your files are small, slow network requests can delay everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Preconnect to important origins&lt;/strong&gt;: If you load resources from third-party domains (Google Analytics, AdSense, CDNs), use &lt;code&gt;&amp;lt;link rel="preconnect"&amp;gt;&lt;/code&gt; to establish the connection early.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://www.googletagmanager.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://pagead2.googlesyndication.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Preload critical resources&lt;/strong&gt;: If you have a critical resource that's discovered late (like a font or an LCP image), use &lt;code&gt;&amp;lt;link rel="preload"&amp;gt;&lt;/code&gt; to tell the browser to fetch it earlier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use a CDN&lt;/strong&gt;: A CDN caches your content at edge locations around the world, so users get it from a server close to them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enable compression&lt;/strong&gt;: Make sure your server (or CDN) is serving gzip or Brotli-compressed files. This can reduce HTML/CSS/JS size by 60-80%.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What Is Preconnect, Exactly?
&lt;/h3&gt;

&lt;p&gt;When the browser loads a resource from a new domain, it has to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do a DNS lookup&lt;/li&gt;
&lt;li&gt;Establish a TCP connection&lt;/li&gt;
&lt;li&gt;Do a TLS handshake (for HTTPS)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's usually 100-300ms of overhead. &lt;code&gt;preconnect&lt;/code&gt; tells the browser to do all this &lt;em&gt;before&lt;/em&gt; it even needs the resource, so when it does need it, the connection is already ready.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Font Optimization
&lt;/h2&gt;

&lt;p&gt;Web fonts are often overlooked, but they can have a big impact on performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;font-display: swap&lt;/code&gt;&lt;/strong&gt;: This tells the browser to show a fallback font immediately, then swap in the custom font when it's ready. Without this, the browser might show invisible text until the font loads.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@font-face&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'MyFont'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;src&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;'/fonts/myfont.woff2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;'woff2'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;font-display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only load the weights you need&lt;/strong&gt;: Don't load 400, 500, 600, 700, 800 if you only use 400 and 700.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subset your fonts&lt;/strong&gt;: If you only use Latin characters, don't load the Chinese/Japanese/Korean subsets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use WOFF2&lt;/strong&gt;: It's the most efficient modern font format, supported by all modern browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Should You Even Use Web Fonts?
&lt;/h3&gt;

&lt;p&gt;For a lot of sites, system fonts are the best choice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;font-family&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;-apple-system&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;BlinkMacSystemFont&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Segoe UI"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;Roboto&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;sans-serif&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;System fonts are already on the user's device, so there's nothing to download. They also look native and feel fast.&lt;/p&gt;

&lt;p&gt;Use web fonts only if you have strong brand reasons to.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. SEO and Crawlability
&lt;/h2&gt;

&lt;p&gt;Performance isn't just about speed — it's also about making sure search engines can actually crawl your site.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use semantic HTML&lt;/strong&gt;: Proper &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; tags help search engines understand your content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add meta descriptions&lt;/strong&gt;: Every page should have a unique &lt;code&gt;&amp;lt;meta name="description"&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generate a sitemap.xml&lt;/strong&gt;: Submit it to Google Search Console.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use structured data (JSON-LD)&lt;/strong&gt;: Add schema.org markup for articles, products, etc. This enables rich snippets in search results.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set &lt;code&gt;lang&lt;/code&gt; attribute&lt;/strong&gt;: &lt;code&gt;&amp;lt;html lang="en"&amp;gt;&lt;/code&gt; helps browsers and search engines know what language your content is in.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7. Accessibility
&lt;/h2&gt;

&lt;p&gt;Accessibility isn't just the right thing to do — it also improves SEO and UX.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Add &lt;code&gt;alt&lt;/code&gt; text to images&lt;/strong&gt;: Screen readers use it, and Google uses it to understand images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use ARIA labels on icon buttons&lt;/strong&gt;: Icon-only buttons need &lt;code&gt;aria-label&lt;/code&gt; so screen readers know what they do.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add skip links&lt;/strong&gt;: Let keyboard users skip past navigation and jump straight to the main content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ensure color contrast&lt;/strong&gt;: Text should have at least 4.5:1 contrast ratio with its background.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  8. The Quick Wins (Do These First)
&lt;/h2&gt;

&lt;p&gt;If you don't have time for everything, do these first — they give you the biggest bang for your buck:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Compress images&lt;/strong&gt; — usually the #1 biggest win&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add &lt;code&gt;width&lt;/code&gt;/&lt;code&gt;height&lt;/code&gt; to images&lt;/strong&gt; — fixes CLS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Defer non-critical JS&lt;/strong&gt; — improves TBT&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async load non-critical CSS&lt;/strong&gt; — improves FCP&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preconnect to third-party domains&lt;/strong&gt; — improves LCP&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  How to Measure
&lt;/h2&gt;

&lt;p&gt;You can't improve what you don't measure. Use these tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PageSpeed Insights&lt;/strong&gt;: Google's official tool, measures Core Web Vitals&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WebPageTest&lt;/strong&gt;: More detailed waterfall analysis, test from different locations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chrome DevTools Performance tab&lt;/strong&gt;: See exactly what's slowing down your page&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lighthouse&lt;/strong&gt;: Built into Chrome DevTools, gives you an overall score&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run the test, fix the top issues, then run it again. Repeat.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Static sites have a huge performance advantage out of the box, but that advantage evaporates if you load hundreds of KB of images, CSS, and JS unnecessarily.&lt;/p&gt;

&lt;p&gt;The good news is that most performance problems are fixable with small, targeted changes. You don't need to rewrite your whole site — you just need to know what to look for.&lt;/p&gt;

&lt;p&gt;Start with the quick wins, measure, and iterate. Over time, you'll get that PageSpeed score from 50 to 90+.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This checklist was compiled from real-world optimization work on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;. If you have questions or want to share your own tips, feel free to reach out.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webperf</category>
      <category>frontend</category>
      <category>performance</category>
    </item>
    <item>
      <title>JavaScript Defer vs Async: A Complete Guide</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 00:40:58 +0000</pubDate>
      <link>https://dev.to/whjin/javascript-defer-vs-async-a-complete-guide-3gbd</link>
      <guid>https://dev.to/whjin/javascript-defer-vs-async-a-complete-guide-3gbd</guid>
      <description>&lt;h1&gt;
  
  
  JavaScript Defer vs Async: A Complete Guide
&lt;/h1&gt;

&lt;p&gt;If you've ever looked at how scripts are loaded in HTML, you've probably seen &lt;code&gt;defer&lt;/code&gt; and &lt;code&gt;async&lt;/code&gt; attributes. They both sound like they make your page faster — and they do — but they work in completely different ways.&lt;/p&gt;

&lt;p&gt;Get them wrong, and you'll end up with subtle bugs that are hard to debug. Get them right, and you'll see a noticeable improvement in page load performance.&lt;/p&gt;

&lt;p&gt;In this guide, we'll break down exactly how &lt;code&gt;defer&lt;/code&gt; and &lt;code&gt;async&lt;/code&gt; work, when to use each, and what common pitfalls to avoid.&lt;/p&gt;




&lt;h2&gt;
  
  
  First: How Scripts Load By Default
&lt;/h2&gt;

&lt;p&gt;Let's start with the basics. When the browser encounters a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag without any attributes, here's what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The browser &lt;strong&gt;pauses HTML parsing&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It downloads the script file&lt;/li&gt;
&lt;li&gt;It executes the script&lt;/li&gt;
&lt;li&gt;Then it resumes HTML parsing&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is called "render-blocking." The browser can't render the page until it's done with the script.&lt;/p&gt;

&lt;p&gt;This is bad for performance because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The longer the script takes to download, the longer users wait to see content&lt;/li&gt;
&lt;li&gt;The longer the script takes to execute, the longer the page feels frozen&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's where &lt;code&gt;defer&lt;/code&gt; and &lt;code&gt;async&lt;/code&gt; come in.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Does &lt;code&gt;defer&lt;/code&gt; Do?
&lt;/h2&gt;

&lt;p&gt;When you add &lt;code&gt;defer&lt;/code&gt; to a script tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The browser &lt;strong&gt;continues HTML parsing&lt;/strong&gt; while downloading the script in the background&lt;/li&gt;
&lt;li&gt;It &lt;strong&gt;waits until HTML parsing is complete&lt;/strong&gt; before executing the script&lt;/li&gt;
&lt;li&gt;Multiple &lt;code&gt;defer&lt;/code&gt; scripts execute &lt;strong&gt;in order&lt;/strong&gt; (the order they appear in the HTML)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Key Properties of &lt;code&gt;defer&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Doesn't block HTML parsing&lt;/li&gt;
&lt;li&gt;✅ Scripts execute in order&lt;/li&gt;
&lt;li&gt;✅ Executes before &lt;code&gt;DOMContentLoaded&lt;/code&gt; event fires&lt;/li&gt;
&lt;li&gt;✅ Scripts can safely access the DOM (because parsing is done)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use &lt;code&gt;defer&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;defer&lt;/code&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your script depends on the DOM being fully parsed&lt;/li&gt;
&lt;li&gt;Your scripts depend on each other (script B needs script A to be loaded first)&lt;/li&gt;
&lt;li&gt;You want to improve page load performance without changing script order&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, &lt;strong&gt;most scripts should be &lt;code&gt;defer&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Does &lt;code&gt;async&lt;/code&gt; Do?
&lt;/h2&gt;

&lt;p&gt;When you add &lt;code&gt;async&lt;/code&gt; to a script tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The browser &lt;strong&gt;continues HTML parsing&lt;/strong&gt; while downloading the script in the background&lt;/li&gt;
&lt;li&gt;As soon as the script finishes downloading, the browser &lt;strong&gt;pauses parsing&lt;/strong&gt; and executes it&lt;/li&gt;
&lt;li&gt;Then it resumes parsing&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Key Properties of &lt;code&gt;async&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Doesn't block HTML parsing (most of the time)&lt;/li&gt;
&lt;li&gt;❌ Scripts execute &lt;strong&gt;in whatever order they finish downloading&lt;/strong&gt; — not the order they appear in the HTML&lt;/li&gt;
&lt;li&gt;❌ Scripts might execute before DOM parsing is complete&lt;/li&gt;
&lt;li&gt;❌ You can't rely on the order of execution&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use &lt;code&gt;async&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;async&lt;/code&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your script is completely independent (doesn't depend on other scripts)&lt;/li&gt;
&lt;li&gt;Your script doesn't need to access the DOM immediately&lt;/li&gt;
&lt;li&gt;Examples: analytics, ads, third-party widgets that don't affect the page layout&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Side-by-Side Comparison
&lt;/h2&gt;

&lt;p&gt;Let's visualize how they work:&lt;/p&gt;

&lt;h3&gt;
  
  
  No Attributes (Blocking)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML Parsing  ████████████████
Script Download         ████
Script Execute               ████
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser pauses parsing while it downloads and executes the script.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;defer&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML Parsing  ████████████████
Script Download      ████
Script Execute                  ████
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download happens in parallel with parsing. Execution waits until parsing is done.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;async&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML Parsing  ██████████
Script Download      ████
Script Execute          ████
HTML Parsing           ██████████
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download happens in parallel. As soon as it's done, execution pauses parsing, runs the script, then resumes parsing.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Pitfalls
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pitfall 1: Assuming &lt;code&gt;async&lt;/code&gt; Scripts Execute in Order
&lt;/h3&gt;

&lt;p&gt;This is the most common mistake. If you have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"a.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"b.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's no guarantee that &lt;code&gt;a.js&lt;/code&gt; executes before &lt;code&gt;b.js&lt;/code&gt;. If &lt;code&gt;b.js&lt;/code&gt; finishes downloading first, it runs first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: If script B depends on script A, use &lt;code&gt;defer&lt;/code&gt; instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pitfall 2: Using &lt;code&gt;async&lt;/code&gt; for DOM-Dependent Scripts
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;app.js&lt;/code&gt; tries to access the DOM immediately (e.g., &lt;code&gt;document.querySelector('#app')&lt;/code&gt;), it might run before the DOM is ready.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Either use &lt;code&gt;defer&lt;/code&gt;, or wrap your code in a &lt;code&gt;DOMContentLoaded&lt;/code&gt; event listener.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pitfall 3: Mixing &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"analytics.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's no guarantee of order between &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt; scripts. &lt;code&gt;async&lt;/code&gt; scripts execute as soon as they're ready, which might be before or after &lt;code&gt;defer&lt;/code&gt; scripts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Keep dependencies within the same loading strategy.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-World Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1: Your Main App Script
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Use defer: depends on DOM, might depend on other scripts --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/js/app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your app probably needs to access the DOM and initialize components. &lt;code&gt;defer&lt;/code&gt; ensures the DOM is ready when it runs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 2: Google Analytics
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Use async: independent, doesn't need DOM immediately --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Analytics doesn't affect the page content. It just sends data to Google. It can load whenever.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 3: Multiple Dependent Scripts
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Use defer: they depend on each other --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/js/jquery.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/js/plugin.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- depends on jQuery --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/js/app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- depends on plugin --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;defer&lt;/code&gt; guarantees they execute in order, so jQuery loads first, then the plugin, then your app.&lt;/p&gt;




&lt;h2&gt;
  
  
  What About &lt;code&gt;module&lt;/code&gt; Scripts?
&lt;/h2&gt;

&lt;p&gt;Modern ES modules (&lt;code&gt;&amp;lt;script type="module"&amp;gt;&lt;/code&gt;) behave like &lt;code&gt;defer&lt;/code&gt; by default. They:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't block HTML parsing&lt;/li&gt;
&lt;li&gt;Execute after parsing is done&lt;/li&gt;
&lt;li&gt;Execute in order&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So you don't need to add &lt;code&gt;defer&lt;/code&gt; to module scripts — it's automatic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- This is already deferred-like --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The &lt;code&gt;DOMContentLoaded&lt;/code&gt; Event
&lt;/h2&gt;

&lt;p&gt;One more thing to know: &lt;code&gt;DOMContentLoaded&lt;/code&gt; waits for deferred scripts to finish.&lt;/p&gt;

&lt;p&gt;The order is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HTML parsing finishes&lt;/li&gt;
&lt;li&gt;Deferred scripts execute (in order)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DOMContentLoaded&lt;/code&gt; event fires&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So if you have a &lt;code&gt;DOMContentLoaded&lt;/code&gt; listener, you can be sure all &lt;code&gt;defer&lt;/code&gt; scripts have already run.&lt;/p&gt;

&lt;p&gt;Async scripts don't block &lt;code&gt;DOMContentLoaded&lt;/code&gt; — they might run before or after, depending on when they finish downloading.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Decision Guide
&lt;/h2&gt;

&lt;p&gt;Ask yourself these questions:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Does my script need the DOM to be ready?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yes&lt;/strong&gt; → Use &lt;code&gt;defer&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No&lt;/strong&gt; → Continue to question 2&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Does my script depend on other scripts?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yes&lt;/strong&gt; → Use &lt;code&gt;defer&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No&lt;/strong&gt; → Continue to question 3&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Is my script independent and non-critical?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yes&lt;/strong&gt; → Use &lt;code&gt;async&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No&lt;/strong&gt; → Use &lt;code&gt;defer&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When in doubt, use &lt;code&gt;defer&lt;/code&gt;. It's safer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Performance Impact
&lt;/h2&gt;

&lt;p&gt;How much does this actually matter?&lt;/p&gt;

&lt;p&gt;It depends on how much JS you have. For a typical blog with 100-200KB of JS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Without defer: FCP might be 1-2 seconds slower&lt;/li&gt;
&lt;li&gt;With defer: FCP improves by 30-50%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For heavy apps with 500KB+ of JS, the difference is even bigger.&lt;/p&gt;

&lt;p&gt;The best part? Adding &lt;code&gt;defer&lt;/code&gt; to all your scripts is a one-line change. It's one of the easiest performance wins you can get.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;defer&lt;/code&gt; and &lt;code&gt;async&lt;/code&gt; both help performance, but they're not interchangeable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;defer&lt;/code&gt;&lt;/strong&gt;: Scripts execute in order, after DOM is ready. Use for most of your scripts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;async&lt;/code&gt;&lt;/strong&gt;: Scripts execute whenever they finish downloading. Use for independent, non-critical scripts like analytics.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The biggest mistake people make is using &lt;code&gt;async&lt;/code&gt; when they should use &lt;code&gt;defer&lt;/code&gt;, then wondering why their scripts fail randomly. Remember: if order matters, use &lt;code&gt;defer&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once you understand this distinction, script loading stops being magic and starts being predictable.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article was inspired by performance optimization work on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;. If you have questions, feel free to reach out.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>My AI-Powered Workflow for Full-Stack + Game Development</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 00:40:07 +0000</pubDate>
      <link>https://dev.to/whjin/my-ai-powered-workflow-for-full-stack-game-development-4o2g</link>
      <guid>https://dev.to/whjin/my-ai-powered-workflow-for-full-stack-game-development-4o2g</guid>
      <description>&lt;h1&gt;
  
  
  My AI-Powered Workflow for Full-Stack + Game Development
&lt;/h1&gt;

&lt;p&gt;I wear a lot of hats. In a typical week, I might:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build a full-stack web app (React + Node + PostgreSQL)&lt;/li&gt;
&lt;li&gt;Write some Verilog for an FPGA project&lt;/li&gt;
&lt;li&gt;Prototype a small browser game&lt;/li&gt;
&lt;li&gt;Tweak my personal blog&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's a wide range of skills, and keeping all of them sharp takes a lot of context switching. AI tools have completely changed how I work.&lt;/p&gt;

&lt;p&gt;This isn't another "10 AI tools you need to know" listicle. This is exactly how I use AI in my daily workflow, what works, what doesn't, and how I've adapted over the past year.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem: Context Switching
&lt;/h2&gt;

&lt;p&gt;As a solo developer who does everything, my biggest time sink isn't writing code — it's switching contexts.&lt;/p&gt;

&lt;p&gt;One minute I'm thinking about React hooks state management. The next I'm debugging a SQL query. Then I'm wondering why my game physics feels floaty. Then I'm reading Verilog timing reports.&lt;/p&gt;

&lt;p&gt;Each context switch costs 10-15 minutes of ramp-up time. Multiply that by 20 switches a day, and you've lost half your day.&lt;/p&gt;

&lt;p&gt;AI has helped me reduce this dramatically. Here's how.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Full-Stack Web Development
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Stack
&lt;/h3&gt;

&lt;p&gt;My typical stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend: React / Vue + TypeScript&lt;/li&gt;
&lt;li&gt;Backend: Node.js / Express&lt;/li&gt;
&lt;li&gt;Database: PostgreSQL&lt;/li&gt;
&lt;li&gt;Deployment: Vercel / GitHub Pages&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How I Use AI
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Frontend&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate component boilerplate&lt;/li&gt;
&lt;li&gt;Debug CSS layout issues (yes, even AI still struggles with centering divs)&lt;/li&gt;
&lt;li&gt;Explain unfamiliar libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Backend&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write Express route handlers&lt;/li&gt;
&lt;li&gt;Generate SQL queries from natural language&lt;/li&gt;
&lt;li&gt;Debug async/await issues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Database&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Schema design feedback&lt;/li&gt;
&lt;li&gt;Query optimization suggestions&lt;/li&gt;
&lt;li&gt;Migration scripts&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What Works Well
&lt;/h3&gt;

&lt;p&gt;I once spent 30 minutes debugging a PostgreSQL N+1 query problem. Pasted the code into Claude, and it spotted the issue in 30 seconds. That's the kind of thing AI is great at — pattern matching across code you've seen a hundred times.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Doesn't Work
&lt;/h3&gt;

&lt;p&gt;Complex system design. AI will happily write you a microservices architecture that "scales to millions of users," but it doesn't know that your app only has 100 users. You still need to make the big architecture calls yourself.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Game Development
&lt;/h2&gt;

&lt;p&gt;I build small browser games — usually with Canvas or Phaser.js. Nothing fancy, just weekend projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I Use AI
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Physics&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"How do I implement simple gravity and collision detection in Canvas?"&lt;/li&gt;
&lt;li&gt;"Why does my character feel floaty? Here's my movement code..."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Game loops&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate the game loop structure (requestAnimationFrame, delta time)&lt;/li&gt;
&lt;li&gt;Input handling (keyboard, mouse, touch)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Polish&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Particle effects&lt;/li&gt;
&lt;li&gt;Screen shake&lt;/li&gt;
&lt;li&gt;Sound effect integration&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real Example
&lt;/h3&gt;

&lt;p&gt;Last month I built a small breakout clone. The ball physics felt wrong — it was either too bouncy or not bouncy enough.&lt;/p&gt;

&lt;p&gt;I pasted my collision detection code into Claude, and it pointed out that I wasn't properly reflecting the ball's velocity vector off the paddle. I was just flipping the Y velocity, which made the ball always bounce straight up regardless of where it hit the paddle.&lt;/p&gt;

&lt;p&gt;It explained how to calculate the reflection angle based on where the ball hits the paddle. Fixed it in 5 minutes.&lt;/p&gt;

&lt;p&gt;That's the kind of thing that would've taken me hours of trial and error before AI.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Doesn't Work
&lt;/h3&gt;

&lt;p&gt;Game feel. AI can write the physics, but it can't tell you if the game "feels" right. That's something you have to playtest yourself.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. FPGA / Hardware
&lt;/h2&gt;

&lt;p&gt;I already wrote a separate article about AI and Verilog, so I'll keep this brief.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I Use AI
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write standard building blocks (UART, SPI, PWM)&lt;/li&gt;
&lt;li&gt;Generate testbenches&lt;/li&gt;
&lt;li&gt;Debug obvious bugs&lt;/li&gt;
&lt;li&gt;Explain unfamiliar Verilog code&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Rule
&lt;/h3&gt;

&lt;p&gt;AI writes the boilerplate, I do the architecture and timing closure.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. The Tool Stack
&lt;/h2&gt;

&lt;p&gt;Here's exactly what I use, and when:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;When I Use It&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cursor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Daily driver. Inline autocomplete, chat sidebar.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Claude (web)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;For complex debugging, long code explanations.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GitHub Copilot&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;When I'm in VS Code (not Cursor).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;ChatGPT&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Quick questions, "how do I do X in Y?"&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I don't use all of them every day. Cursor + Claude cover 90% of my needs.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Workflow: Step by Step
&lt;/h2&gt;

&lt;p&gt;Here's what a typical day looks like:&lt;/p&gt;

&lt;h3&gt;
  
  
  Morning: Planning
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;I open my notes and figure out what I'm working on today&lt;/li&gt;
&lt;li&gt;No AI involved — planning is still human territory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Mid-Morning: Implementation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Open Cursor, start coding&lt;/li&gt;
&lt;li&gt;AI autocomplete handles boilerplate&lt;/li&gt;
&lt;li&gt;When I get stuck, I open the chat sidebar and ask&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Afternoon: Debugging
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Something's broken&lt;/li&gt;
&lt;li&gt;Paste the error + relevant code into Claude&lt;/li&gt;
&lt;li&gt;It suggests a fix, I try it&lt;/li&gt;
&lt;li&gt;Iterate&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Evening: Review
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go through what I wrote&lt;/li&gt;
&lt;li&gt;AI-assisted review: "Does this code look okay?"&lt;/li&gt;
&lt;li&gt;Clean up, commit&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Productivity Math
&lt;/h2&gt;

&lt;p&gt;Before AI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing a new CRUD feature: ~4 hours&lt;/li&gt;
&lt;li&gt;Debugging a tricky bug: ~2 hours&lt;/li&gt;
&lt;li&gt;Writing a testbench: ~1 hour&lt;/li&gt;
&lt;li&gt;Total: ~7 hours of focused work&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With AI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing a new CRUD feature: ~2 hours&lt;/li&gt;
&lt;li&gt;Debugging a tricky bug: ~1 hour&lt;/li&gt;
&lt;li&gt;Writing a testbench: ~20 minutes&lt;/li&gt;
&lt;li&gt;Total: ~3.5 hours&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Roughly 2x faster. Not 10x, not "AI replaced me" — just genuinely twice as productive.&lt;/p&gt;

&lt;p&gt;The biggest gain isn't typing speed — it's reducing context switching and mental overhead.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Still Do Manually
&lt;/h2&gt;

&lt;p&gt;AI doesn't do these things for me, and probably never will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Architecture decisions&lt;/strong&gt;: Should I use REST or GraphQL? SQL or NoSQL? AI can give pros and cons, but I make the call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Product judgment&lt;/strong&gt;: What features to build, what to cut. AI doesn't know your users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Game feel&lt;/strong&gt;: Does the game feel fun? AI can't playtest it for you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timing closure&lt;/strong&gt;: FPGA design's hardest problem is still a human job.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code review&lt;/strong&gt;: AI is too nice. It'll approve whatever you give it.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Tips for Getting the Most Out of AI
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Be Specific
&lt;/h3&gt;

&lt;p&gt;Bad: "Write a game."&lt;br&gt;
Good: "Write a simple breakout game in HTML5 Canvas. Ball bounces off paddle and bricks. Score counter. Game over when ball hits bottom."&lt;/p&gt;

&lt;p&gt;The more specific you are, the better the output.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Iterate
&lt;/h3&gt;

&lt;p&gt;First output is never perfect. Treat it like a junior developer's work — review it, give feedback, iterate.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Know When to Stop
&lt;/h3&gt;

&lt;p&gt;If AI has tried 3 times and still can't solve your bug, it's probably a nuanced problem that needs your own debugging skills. Don't waste hours going back and forth.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Don't Blindly Trust
&lt;/h3&gt;

&lt;p&gt;AI hallucinates. It'll confidently write code that looks right but doesn't work. Always test, always review.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;AI hasn't replaced me as a developer. But it has made me significantly more productive — especially across multiple domains.&lt;/p&gt;

&lt;p&gt;The biggest win isn't "AI writes my code for me." It's that I can switch between web dev, game dev, and FPGA work without losing hours of context. AI fills in the gaps when I'm rusty on something I don't do every day.&lt;/p&gt;

&lt;p&gt;If you're a multi-disciplinary developer like me, AI is a force multiplier. It lets you do more things, in more domains, without burning out.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This was based on real daily work across &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt; and various side projects. If you're also a multi-disciplinary developer, I'd love to hear how you use AI tools.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>tools</category>
    </item>
    <item>
      <title>How I Reduced My Blog's CLS from 0.37 to Under 0.1: A Real-World Case Study</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 00:40:06 +0000</pubDate>
      <link>https://dev.to/whjin/how-i-reduced-my-blogs-cls-from-037-to-under-01-a-real-world-case-study-ml</link>
      <guid>https://dev.to/whjin/how-i-reduced-my-blogs-cls-from-037-to-under-01-a-real-world-case-study-ml</guid>
      <description>&lt;h1&gt;
  
  
  How I Reduced My Blog's CLS from 0.37 to Under 0.1: A Real-World Case Study
&lt;/h1&gt;

&lt;p&gt;Cumulative Layout Shift (CLS) is one of those metrics that sounds simple on paper — "how much does the layout shift during page load" — but in practice, it's surprisingly tricky to get right.&lt;/p&gt;

&lt;p&gt;When I ran my blog through PageSpeed Insights, I got a CLS score of &lt;strong&gt;0.37&lt;/strong&gt;. That's way above the recommended threshold of 0.1. Worse, the report didn't give me clear guidance on &lt;em&gt;what&lt;/em&gt; was actually shifting.&lt;/p&gt;

&lt;p&gt;After a week of digging, I got it down to under 0.1. In this article, I'll share exactly what I did, what the common culprits are, and how you can fix them on your own site.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is CLS, Anyway?
&lt;/h2&gt;

&lt;p&gt;Before we dive into fixes, let's make sure we're on the same page.&lt;/p&gt;

&lt;p&gt;CLS measures how much unexpected layout shift happens during a page's lifetime. Every time an element moves from one position to another after the initial render, that's a layout shift.&lt;/p&gt;

&lt;p&gt;Google breaks it down like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Good&lt;/strong&gt;: ≤ 0.1&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Needs improvement&lt;/strong&gt;: 0.1 – 0.25&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Poor&lt;/strong&gt;: &amp;gt; 0.25&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My score of 0.37 was solidly in "poor" territory. The main issue? It wasn't obvious &lt;em&gt;why&lt;/em&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Diagnostic Process
&lt;/h2&gt;

&lt;p&gt;First, I needed to figure out what was actually shifting. PageSpeed Insights gives you a list of "layout shift culprits," but it's not always clear how to fix them.&lt;/p&gt;

&lt;p&gt;Here's the process I followed:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Use Chrome DevTools' Performance Tab
&lt;/h3&gt;

&lt;p&gt;Open DevTools → Performance tab → record a page load.&lt;/p&gt;

&lt;p&gt;Look for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Layout Shift markers&lt;/strong&gt; (purple bars) in the timeline&lt;/li&gt;
&lt;li&gt;Elements that move when you hover over the shift markers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This gave me a clearer picture: the shifts were happening when images loaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Check for Missing Image Dimensions
&lt;/h3&gt;

&lt;p&gt;The most common cause of CLS is images without &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; attributes.&lt;/p&gt;

&lt;p&gt;When the browser doesn't know how big an image is going to be, it reserves zero space for it. Then when the image loads, it suddenly takes up space, pushing everything below it down. That's a layout shift.&lt;/p&gt;

&lt;p&gt;I thought I'd already fixed this. Turns out, I'd only fixed it for &lt;em&gt;static&lt;/em&gt; images in the HTML, not for &lt;em&gt;dynamically rendered&lt;/em&gt; images.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Culprits: What Was Actually Shifting
&lt;/h2&gt;

&lt;p&gt;Let me walk through the specific issues I found and fixed.&lt;/p&gt;




&lt;h3&gt;
  
  
  Issue 1: Dynamic Feed Card Cover Images
&lt;/h3&gt;

&lt;p&gt;My homepage has a feed of article cards. Each card has a cover image on the left, and text content on the right.&lt;/p&gt;

&lt;p&gt;The cards are rendered dynamically with JavaScript. The cover image HTML looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fc-cover"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/images/article-cover.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Article title"&lt;/span&gt; &lt;span class="na"&gt;loading=&lt;/span&gt;&lt;span class="s"&gt;"lazy"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice anything missing? &lt;strong&gt;No &lt;code&gt;width&lt;/code&gt; or &lt;code&gt;height&lt;/code&gt; attributes.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.fc-cover&lt;/code&gt; container had a width set (&lt;code&gt;38%&lt;/code&gt; of the card), but no fixed height. So before the image loaded, the container was 0px tall. When the image loaded, it suddenly expanded to ~180px, pushing the text content down.&lt;/p&gt;

&lt;p&gt;That's a layout shift. Every single card on the page was causing one.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;

&lt;p&gt;I had two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Add &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; attributes to the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Set &lt;code&gt;aspect-ratio&lt;/code&gt; on the container&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I went with option 2 because it's more flexible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.feed-card.fc-has-cover&lt;/span&gt; &lt;span class="nc"&gt;.fc-cover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;38%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;280px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;aspect-ratio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c"&gt;/* ← This line! */&lt;/span&gt;
  &lt;span class="nl"&gt;flex-shrink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;aspect-ratio: 16 / 9&lt;/code&gt; tells the browser: "this container should always be 16:9, regardless of what's inside." So even before the image loads, the container already has the correct height. No more shift when the image pops in.&lt;/p&gt;

&lt;p&gt;This single fix eliminated the majority of my CLS.&lt;/p&gt;




&lt;h3&gt;
  
  
  Issue 2: Advertisement Units
&lt;/h3&gt;

&lt;p&gt;The second culprit was Google AdSense ads.&lt;/p&gt;

&lt;p&gt;Ads load asynchronously. When they finally render, they inject content into the page, pushing everything below them down.&lt;/p&gt;

&lt;p&gt;This is a notoriously hard problem because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don't know how tall the ad will be ahead of time&lt;/li&gt;
&lt;li&gt;Different ad sizes fit in the same slot&lt;/li&gt;
&lt;li&gt;You can't control what Google serves&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;

&lt;p&gt;The best practical solution is to &lt;strong&gt;reserve space for ads upfront&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Pick a standard ad size (e.g., 300x250 for a rectangle, or 728x90 for a leaderboard) and set that as the minimum height of the ad container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.ad-slot&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c"&gt;/* ← Reserve space */&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, even before the ad loads, the container already takes up the right amount of space. The ad fills in when it's ready, and nothing shifts.&lt;/p&gt;

&lt;p&gt;It's not perfect — if Google serves a smaller ad, you'll have some empty space. But it's better than layout shifts.&lt;/p&gt;




&lt;h3&gt;
  
  
  Issue 3: Web Fonts
&lt;/h3&gt;

&lt;p&gt;The third culprit was web fonts.&lt;/p&gt;

&lt;p&gt;When a web font loads, it can cause a "font swap" — the browser first shows a fallback font, then swaps in the custom font. If the custom font has different metrics (wider, taller, etc.), the text reflows, causing layout shifts.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;font-display: swap&lt;/code&gt; and make sure your fallback font is as close as possible in metrics.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@font-face&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'MyCustomFont'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;src&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;'/fonts/myfont.woff2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;'woff2'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;font-display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For even better results, you can use &lt;code&gt;size-adjust&lt;/code&gt; and &lt;code&gt;ascent-override&lt;/code&gt; to make the fallback font match the custom font's metrics more closely.&lt;/p&gt;

&lt;p&gt;In my case, I was using system fonts, so this wasn't a big issue. But it's worth checking if you use custom web fonts.&lt;/p&gt;




&lt;h3&gt;
  
  
  Issue 4: Late-Injected UI Elements
&lt;/h3&gt;

&lt;p&gt;The fourth issue was UI elements that were injected into the page after initial render.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cookie consent banners that pop up a few seconds after load&lt;/li&gt;
&lt;li&gt;Notification bars&lt;/li&gt;
&lt;li&gt;Floating action buttons&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These elements appear suddenly, pushing content down.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;

&lt;p&gt;Reserve space for them upfront, or make them &lt;strong&gt;overlay&lt;/strong&gt; elements (position: fixed/absolute) instead of in-flow elements.&lt;/p&gt;

&lt;p&gt;Cookie consent banners are usually fixed at the bottom, so they overlay content rather than pushing it. That's fine for CLS. But if you have an inline banner that pushes content down, you need to account for it.&lt;/p&gt;

&lt;p&gt;In my case, the cookie consent banner was already &lt;code&gt;position: fixed&lt;/code&gt;, so it wasn't contributing to CLS. But it's worth checking.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Results
&lt;/h2&gt;

&lt;p&gt;After these fixes, my CLS score dropped from &lt;strong&gt;0.37&lt;/strong&gt; to under &lt;strong&gt;0.1&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CLS&lt;/td&gt;
&lt;td&gt;0.37 (Poor)&lt;/td&gt;
&lt;td&gt;&amp;lt; 0.1 (Good)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LCP&lt;/td&gt;
&lt;td&gt;1.3s&lt;/td&gt;
&lt;td&gt;1.3s (unchanged)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FCP&lt;/td&gt;
&lt;td&gt;387ms&lt;/td&gt;
&lt;td&gt;387ms (unchanged)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The best part? None of these fixes required a rewrite. They were all small, targeted changes.&lt;/p&gt;




&lt;h2&gt;
  
  
  CLS Checklist: What to Check on Your Site
&lt;/h2&gt;

&lt;p&gt;Use this checklist to audit your own site:&lt;/p&gt;

&lt;h3&gt;
  
  
  Images
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Do all &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tags have &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; attributes?&lt;/li&gt;
&lt;li&gt;[ ] Do dynamically rendered images have dimensions?&lt;/li&gt;
&lt;li&gt;[ ] Do image containers have &lt;code&gt;aspect-ratio&lt;/code&gt; set?&lt;/li&gt;
&lt;li&gt;[ ] Do background images have reserved space?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ads
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Do ad slots have a &lt;code&gt;min-height&lt;/code&gt; set?&lt;/li&gt;
&lt;li&gt;[ ] Are ad sizes standardized?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Fonts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Are you using &lt;code&gt;font-display: swap&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;[ ] Do your fallback fonts match your custom font's metrics?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  UI Elements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Are cookie banners fixed/overlay (not in-flow)?&lt;/li&gt;
&lt;li&gt;[ ] Are notification bars reserved upfront?&lt;/li&gt;
&lt;li&gt;[ ] Are floating buttons fixed (not in-flow)?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Embedded Content
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Do &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt; tags have &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;[ ] Do video embeds have reserved space?&lt;/li&gt;
&lt;li&gt;[ ] Do social media embeds have reserved space?&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common Myths Debunked
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Myth 1: "CLS only affects mobile"
&lt;/h3&gt;

&lt;p&gt;Nope. CLS matters on desktop too. Google's Core Web Vitals are measured on mobile, but good CLS is good CLS regardless of device.&lt;/p&gt;

&lt;h3&gt;
  
  
  Myth 2: "If I don't see shifts, my CLS is fine"
&lt;/h3&gt;

&lt;p&gt;You might not notice shifts if you're on a fast connection with fast cache. But users on slower networks will see more shifts because images and ads take longer to load. Always test with throttling.&lt;/p&gt;

&lt;h3&gt;
  
  
  Myth 3: "CLS doesn't matter much for SEO"
&lt;/h3&gt;

&lt;p&gt;It does. CLS is one of the three Core Web Vitals, and Google explicitly uses it as a ranking signal. A poor CLS can hurt your search rankings.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;CLS is one of those metrics that's easy to ignore because it doesn't directly affect functionality. Users might not consciously notice the shifts, but they do affect perceived performance — the site feels "janky" or "unpolished."&lt;/p&gt;

&lt;p&gt;The good news is that fixing CLS is usually straightforward once you know what to look for. The vast majority of layout shifts come down to one thing: &lt;strong&gt;elements changing size after initial render&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you remember nothing else from this article, remember this: &lt;strong&gt;always reserve space for elements that load asynchronously&lt;/strong&gt;. Images, ads, embeds — anything that pops in later needs to have its space accounted for upfront.&lt;/p&gt;

&lt;p&gt;Once you've done that, CLS mostly takes care of itself.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This was based on real-world optimization work on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;. If you have questions or want to share your own CLS fixes, feel free to reach out.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webperf</category>
      <category>frontend</category>
      <category>performance</category>
    </item>
    <item>
      <title>Can AI Actually Write Verilog for FPGAs? My Real-World Test</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 00:38:25 +0000</pubDate>
      <link>https://dev.to/whjin/can-ai-actually-write-verilog-for-fpgas-my-real-world-test-led</link>
      <guid>https://dev.to/whjin/can-ai-actually-write-verilog-for-fpgas-my-real-world-test-led</guid>
      <description>&lt;h1&gt;
  
  
  Can AI Actually Write Verilog for FPGAs? My Real-World Test
&lt;/h1&gt;

&lt;p&gt;As someone who does both full-stack web development and FPGA/Verilog programming, I was curious: can AI coding assistants handle hardware description languages?&lt;/p&gt;

&lt;p&gt;Everyone's talking about AI writing JavaScript, Python, and Rust. But what about Verilog? VHDL? Can an LLM actually understand hardware parallelism, timing constraints, and FPGA-specific quirks?&lt;/p&gt;

&lt;p&gt;I decided to put it to the test. Over the past month, I've been using AI tools (Claude, GPT-4, Cursor) on real FPGA projects. Here's what worked, what didn't, and whether AI is actually useful for hardware design.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I Was Skeptical
&lt;/h2&gt;

&lt;p&gt;I'm a self-taught FPGA developer. I know Verilog well enough to design working circuits, but I'm not a seasoned ASIC engineer. So I was hopeful that AI could help — but also skeptical.&lt;/p&gt;

&lt;p&gt;Hardware description languages are fundamentally different from software:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Parallel execution&lt;/strong&gt;: Everything happens at once, not step by step&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timing matters&lt;/strong&gt;: A bug that only shows up at 100MHz might be invisible in simulation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource constraints&lt;/strong&gt;: FPGAs have fixed LUTs, flip-flops, and DSP blocks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Toolchain quirks&lt;/strong&gt;: Every FPGA vendor (Xilinx, Intel, Lattice) has its own weirdness&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Could an LLM actually grok this?&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 1: Basic Modules
&lt;/h2&gt;

&lt;p&gt;Let's start simple. I asked Claude to write a UART transmitter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "Write a Verilog module for a UART transmitter, 115200 baud, 8N1, 50MHz clock."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It wrote a clean, well-structured UART transmitter. It had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A baud rate generator&lt;/li&gt;
&lt;li&gt;A shift register&lt;/li&gt;
&lt;li&gt;Start/stop bit logic&lt;/li&gt;
&lt;li&gt;Even added a parity bit option&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Was it correct? Mostly. I had to tweak the baud rate divisor calculation (it used 50MHz / 115200 ≈ 434, which is right), but the structure was solid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ✅ Works well for standard building blocks. UART, SPI, I2C, PWM — all the common interfaces.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 2: State Machines
&lt;/h2&gt;

&lt;p&gt;Next, I asked for a more complex design: a SPI master with a configurable register file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "Write a Verilog SPI master module that can read/write to internal registers, 4-wire SPI, mode 0."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: The output was good. It had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proper SPI mode 0 timing (CPOL=0, CPHA=0)&lt;/li&gt;
&lt;li&gt;A state machine for the SPI transaction&lt;/li&gt;
&lt;li&gt;An internal register bank&lt;/li&gt;
&lt;li&gt;Chip select handling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One thing it got wrong: it used a blocking assignment (&lt;code&gt;=&lt;/code&gt;) in a sequential block where it should have used non-blocking (&lt;code&gt;&amp;lt;=&lt;/code&gt;). This is a classic Verilog gotcha — the kind of thing that simulation might not catch, but synthesis will hate.&lt;/p&gt;

&lt;p&gt;I caught it because I know what to look for. A beginner might not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ⚠️ Good structure, but watch for subtle Verilog mistakes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 3: Timing and Constraints
&lt;/h2&gt;

&lt;p&gt;Here's where things get interesting. Timing closure is one of the hardest parts of FPGA design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "My design has a 100MHz clock and I'm getting setup time violations. How do I fix this?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It gave the standard advice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add pipeline registers&lt;/li&gt;
&lt;li&gt;Retime logic&lt;/li&gt;
&lt;li&gt;Use FPGA's built-in RAM blocks&lt;/li&gt;
&lt;li&gt;Check for combinational loops&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All good advice — but generic. It couldn't actually look at my specific timing report and tell me which path was the problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ⚠️ Good theoretical advice, but can't analyze your specific timing report.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 4: Debugging Existing Code
&lt;/h2&gt;

&lt;p&gt;This is where I was most curious. Can AI help debug broken Verilog?&lt;/p&gt;

&lt;p&gt;I took a working SPI module and introduced a bug: I swapped the MOSI and MISO signals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "My SPI receiver isn't working. The data I'm getting is all zeros. Here's my code: [pasted Verilog]"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It read through the code, spotted the MISO/MOSI mix-up within seconds. It explained why it was wrong and how to fix it.&lt;/p&gt;

&lt;p&gt;Impressive. But let's be honest — this was a simple bug. What about trickier ones?&lt;/p&gt;

&lt;p&gt;I tried a more subtle bug: a metastability issue where I forgot to double-synchronize an asynchronous input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "I'm getting random bit errors on my UART RX line. The design works in simulation but fails on hardware."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It suggested checking for metastability issues. It mentioned that asynchronous inputs need proper synchronization. But it didn't pinpoint the exact issue because it couldn't see my full design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ✅ Great for spotting obvious bugs. ⚠️ Harder for subtle timing/metastability issues.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 5: FPGA-Specific Knowledge
&lt;/h2&gt;

&lt;p&gt;What about FPGA vendor-specific stuff? Like Xilinx UltraRAM, or Intel DSP blocks?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "Write a Verilog design that uses a Xilinx DSP48E2 block to implement a FIR filter."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It wrote the structure, but the DSP48E2 instantiation was wrong. It used generic names instead of the actual Xilinx primitive names.&lt;/p&gt;

&lt;p&gt;You'd need to know the exact primitive names, ports, and parameters — which AI doesn't always get right.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ⚠️ Good for generic logic, but vendor-specific primitives need manual correction.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Actually Saves Me Time
&lt;/h2&gt;

&lt;p&gt;After a month of using AI on FPGA projects, here's what actually saves time:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Boilerplate and Common Interfaces
&lt;/h3&gt;

&lt;p&gt;UART, SPI, I2C, PWM, I2S — all the standard building blocks. AI writes these correctly 90% of the time, saving me hours of looking up reference code.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Testbenches
&lt;/h3&gt;

&lt;p&gt;Writing testbenches is tedious. AI is surprisingly good at them. Ask it to "write a testbench for this UART module that sends 0x55 and 0xAA and checks the output" — it does it.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Explaining Existing Code
&lt;/h3&gt;

&lt;p&gt;Staring at someone else's Verilog for hours? Paste it into Claude and ask "what does this do?" It's surprisingly good at reverse-engineering.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Debugging Obvious Bugs
&lt;/h3&gt;

&lt;p&gt;Syntax errors, wrong port directions, missing &lt;code&gt;endmodule&lt;/code&gt; — AI catches these instantly.&lt;/p&gt;




&lt;h2&gt;
  
  
  What AI Still Sucks At
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Timing Closure
&lt;/h3&gt;

&lt;p&gt;This is the hard part of FPGA design. AI can't read your timing report and tell you exactly which path to fix. You still need to understand setup/hold time, clock skew, and retiming yourself.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Resource Optimization
&lt;/h3&gt;

&lt;p&gt;"Can I fit this design into a Lattice iCE40 with 1280 LUTs?" AI can estimate, but it can't actually run synthesis and see the real resource usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Vendor-Specific Tooling
&lt;/h3&gt;

&lt;p&gt;Xilinx Vivado, Intel Quartus, Lattice iCEcube2 — each has its own Tcl scripting, constraints format, and build flow. AI doesn't know the ins and outs of your specific toolchain.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Subtle Hardware Bugs
&lt;/h3&gt;

&lt;p&gt;Metastability, race conditions, glitches — these are the bugs that don't show up in simulation but eat you alive on real hardware. AI won't catch these unless you explicitly point them out.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Workflow Now
&lt;/h2&gt;

&lt;p&gt;Here's how I actually use AI for FPGA work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Design phase&lt;/strong&gt;: I sketch the block diagram myself. AI doesn't make architectural decisions for me.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation&lt;/strong&gt;: I ask AI to write the boilerplate modules (UART, SPI, etc.).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration&lt;/strong&gt;: I wire everything together manually.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testbench&lt;/strong&gt;: AI writes the testbench.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging&lt;/strong&gt;: If simulation fails, I paste the code and ask AI for help.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synthesis&lt;/strong&gt;: I run the tools myself. AI doesn't touch the timing constraints.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;AI is a copilot, not the pilot. It handles the tedious parts, I handle the architecture and the tricky bits.&lt;/p&gt;




&lt;h2&gt;
  
  
  Should FPGA Developers Use AI?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yes, with caveations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI is great for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing standard building blocks&lt;/li&gt;
&lt;li&gt;Generating testbenches&lt;/li&gt;
&lt;li&gt;Debugging obvious bugs&lt;/li&gt;
&lt;li&gt;Explaining unfamiliar code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI is NOT good for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Architectural decisions&lt;/li&gt;
&lt;li&gt;Timing closure&lt;/li&gt;
&lt;li&gt;Vendor-specific optimization&lt;/li&gt;
&lt;li&gt;Subtle hardware bugs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of AI as a junior engineer. It can crank out working code for well-defined tasks, but you still need to review it carefully. And for the hard problems — timing, resources, architecture — you're still the one in charge.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;AI won't replace FPGA engineers anytime soon. Hardware design is too nuanced, too tied to specific hardware, too dependent on real-world measurement.&lt;/p&gt;

&lt;p&gt;But AI will make FPGA developers more productive. The tedious boilerplate that used to take hours? Now it takes minutes. The time saved can go into the hard parts — architecture, optimization, testing — where it actually matters.&lt;/p&gt;

&lt;p&gt;If you're an FPGA developer and you're not using AI yet, you're spending too much time writing UART and SPI modules from scratch.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This was based on real FPGA development work on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;. If you're also doing FPGA + software development, I'd love to hear how you're using AI tools.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>fpga</category>
      <category>verilog</category>
      <category>hardware</category>
    </item>
    <item>
      <title>AI Coding Assistants in 2026: A Frontend Developer's Honest Review</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Thu, 05 Nov 2026 00:38:24 +0000</pubDate>
      <link>https://dev.to/whjin/ai-coding-assistants-in-2026-a-frontend-developers-honest-review-2672</link>
      <guid>https://dev.to/whjin/ai-coding-assistants-in-2026-a-frontend-developers-honest-review-2672</guid>
      <description>&lt;h1&gt;
  
  
  AI Coding Assistants in 2026: A Frontend Developer's Honest Review
&lt;/h1&gt;

&lt;p&gt;Three years ago, AI coding assistants were basically fancy autocomplete tools. They'd suggest the next line of code based on what you'd typed so far, and half the time it was wrong.&lt;/p&gt;

&lt;p&gt;Fast forward to 2026, and the landscape is completely different. We now have AI tools that can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand your entire codebase&lt;/li&gt;
&lt;li&gt;Debug complex errors&lt;/li&gt;
&lt;li&gt;Refactor entire components&lt;/li&gt;
&lt;li&gt;Write tests from scratch&lt;/li&gt;
&lt;li&gt;Even run commands and fix things themselves&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But which ones are actually worth your time? And are they as good as the hype says?&lt;/p&gt;

&lt;p&gt;I've been using AI coding tools daily for the past year, across dozens of projects. Here's my honest, no-sponsored review of the main options.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Contenders
&lt;/h2&gt;

&lt;p&gt;Let's define the playing field. As of 2026, the main AI coding assistants for frontend developers are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Copilot&lt;/strong&gt; — the incumbent, integrated into VS Code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cursor&lt;/strong&gt; — the AI-first editor, built from the ground up around AI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Claude Code&lt;/strong&gt; — Anthropic's CLI-based coding agent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Codeium&lt;/strong&gt; — the free alternative&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Windsurf&lt;/strong&gt; — Codeium's AI IDE&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I've used all of them extensively. Here's how they compare.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. GitHub Copilot
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Does
&lt;/h3&gt;

&lt;p&gt;Copilot sits in your editor and gives you inline suggestions as you type. It's evolved from simple autocomplete to something much smarter.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Good
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ubiquitous&lt;/strong&gt;: It's right there in VS Code, no need to switch tools&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast&lt;/strong&gt;: Suggestions appear instantly, no context switching&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Good at boilerplate&lt;/strong&gt;: Writing repetitive CRUD code? Copilot nails it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LSP integration&lt;/strong&gt;: It understands your project's types and imports&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Bad
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Context window is limited&lt;/strong&gt;: It doesn't deeply understand your entire codebase&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hallucinates confidently&lt;/strong&gt;: It'll suggest code that looks right but doesn't work&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One-shot suggestions&lt;/strong&gt;: You can't have a back-and-forth conversation with it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pricing&lt;/strong&gt;: $10/month for individuals, but enterprise pricing gets steep&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Best For
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Writing boilerplate and repetitive code&lt;/li&gt;
&lt;li&gt;Quick autocomplete while you're in the zone&lt;/li&gt;
&lt;li&gt;Teams already using GitHub&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Cursor
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Does
&lt;/h3&gt;

&lt;p&gt;Cursor is a fork of VS Code that's been heavily modified around AI. It's not just an extension — it's the whole editor built around AI-first workflows.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Good
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Codebase awareness&lt;/strong&gt;: It can search and understand your entire project, not just the open file&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tab to accept&lt;/strong&gt;: The "Tab to accept" UX is incredibly smooth — you just keep pressing Tab to build code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chat sidebar&lt;/strong&gt;: You can have a conversation about your code without leaving the editor&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Composer mode&lt;/strong&gt;: It can make changes across multiple files at once&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Good at refactoring&lt;/strong&gt;: "Refactor this component to use hooks" actually works&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Bad
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It's another editor&lt;/strong&gt;: If you're used to VS Code's setup, migrating takes effort&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Can be slow&lt;/strong&gt;: For large codebases, the AI features can feel sluggish&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pricing&lt;/strong&gt;: $20/month, which is steeper than Copilot&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Occasionally over-engineers&lt;/strong&gt;: It sometimes adds complexity you didn't ask for&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Best For
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Developers who want deep AI integration&lt;/li&gt;
&lt;li&gt;Larger codebases where you need cross-file understanding&lt;/li&gt;
&lt;li&gt;Anyone who spends more time thinking than typing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Claude Code
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Does
&lt;/h3&gt;

&lt;p&gt;Claude Code is Anthropic's CLI-based coding agent. It runs in your terminal, can read your codebase, run commands, and make changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Good
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Best reasoning&lt;/strong&gt;: Claude models are genuinely the best at understanding complex code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Can run commands&lt;/strong&gt;: It can actually run tests, fix errors, and iterate&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Great at debugging&lt;/strong&gt;: Describe the error, and it'll trace through the code to find the root cause&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Long context window&lt;/strong&gt;: Can handle huge files or multiple files at once&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Bad
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CLI only&lt;/strong&gt;: No GUI, which is a dealbreaker for some&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Slower than IDE-based tools&lt;/strong&gt;: You're working in the terminal, not in the editor&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expensive&lt;/strong&gt;: API-based pricing can add up fast&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No autocomplete&lt;/strong&gt;: It's for big tasks, not inline suggestions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Best For
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Complex debugging sessions&lt;/li&gt;
&lt;li&gt;Large refactoring tasks&lt;/li&gt;
&lt;li&gt;Developers who live in the terminal&lt;/li&gt;
&lt;li&gt;Tasks that require deep reasoning&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Codeium / Windsurf
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Does
&lt;/h3&gt;

&lt;p&gt;Codeium started as a free Copilot alternative, then evolved into Windsurf — a full AI IDE.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Good
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Free tier is generous&lt;/strong&gt;: You can use it without paying&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Good autocomplete quality&lt;/strong&gt;: Surprisingly good for a free tool&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Windsurf IDE&lt;/strong&gt;: Solid VS Code alternative with AI built in&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Bad
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not as good as the top tier&lt;/strong&gt;: The suggestions are hit-or-miss compared to Copilot/Cursor&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weaker reasoning&lt;/strong&gt;: For complex tasks, it's not in the same league as Claude&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smaller ecosystem&lt;/strong&gt;: Fewer integrations, less community support&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Best For
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Budget-conscious developers&lt;/li&gt;
&lt;li&gt;Students and hobby projects&lt;/li&gt;
&lt;li&gt;Anyone who wants AI features without paying&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How I Actually Use Them
&lt;/h2&gt;

&lt;p&gt;Here's my daily workflow:&lt;/p&gt;

&lt;h3&gt;
  
  
  In the Editor
&lt;/h3&gt;

&lt;p&gt;I use &lt;strong&gt;Cursor&lt;/strong&gt; as my main editor. The Tab-to-accept workflow is just too smooth to go back.&lt;/p&gt;

&lt;p&gt;For inline autocomplete, Cursor's built-in AI is good enough that I don't need Copilot anymore.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Complex Tasks
&lt;/h3&gt;

&lt;p&gt;When I hit a tricky bug or need to refactor something non-trivial, I switch to &lt;strong&gt;Claude Code&lt;/strong&gt; in the terminal. It's way better at reasoning through complex problems than the IDE-based tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Quick Questions
&lt;/h3&gt;

&lt;p&gt;If I just need to look up syntax or remember an API, I'll ask the chat sidebar in Cursor.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Real Truth: What AI Actually Sucks At
&lt;/h2&gt;

&lt;p&gt;AI coding tools are great, but they're not magic. Here's what they still struggle with:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Architecture Decisions
&lt;/h3&gt;

&lt;p&gt;AI will happily write you 500 lines of code that "works," but it won't tell you that you're choosing the wrong architecture. You still need to make the big-picture decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Understanding Product Requirements
&lt;/h3&gt;

&lt;p&gt;AI doesn't know what your users want. It can write code, but it can't decide what code to write.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Subtle Bugs
&lt;/h3&gt;

&lt;p&gt;AI is great at writing new code, but terrible at debugging weird edge cases. The bug that only happens in production at 3am? You'll still be debugging that yourself.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Code Review
&lt;/h3&gt;

&lt;p&gt;AI can generate code, but can it review your code objectively? Mostly no. It tends to approve whatever you give it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Productivity Question
&lt;/h2&gt;

&lt;p&gt;So, do AI coding assistants actually make you faster?&lt;/p&gt;

&lt;p&gt;Based on my experience:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Writing new features&lt;/strong&gt;: 30-50% faster&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Writing tests&lt;/strong&gt;: 2x faster&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging known issues&lt;/strong&gt;: 20-30% faster&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging weird production bugs&lt;/strong&gt;: Not much help&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code review&lt;/strong&gt;: No help at all&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The biggest win isn't speed — it's &lt;strong&gt;reducing context switching&lt;/strong&gt;. Instead of Googling syntax, opening Stack Overflow, and copying code, you just ask the AI and move on.&lt;/p&gt;

&lt;p&gt;That mental overhead reduction is where the real value is.&lt;/p&gt;




&lt;h2&gt;
  
  
  Should You Switch?
&lt;/h2&gt;

&lt;p&gt;If you're still not using any AI coding tool in 2026, you're leaving productivity on the table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start with Copilot&lt;/strong&gt; if you want the safest, most integrated option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try Cursor&lt;/strong&gt; if you want the best all-around AI IDE experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Claude Code&lt;/strong&gt; when you hit hard problems that the IDE tools can't solve.&lt;/p&gt;

&lt;p&gt;The best setup isn't one tool — it's using the right tool for the right task.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;AI coding is evolving fast. In the next year, I expect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Even better codebase understanding&lt;/li&gt;
&lt;li&gt;AI that can run your tests and fix failures autonomously&lt;/li&gt;
&lt;li&gt;More specialized models for specific languages/frameworks&lt;/li&gt;
&lt;li&gt;Better integration between design tools and code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tools will keep getting better. But the developers who know how to use them effectively will always be ahead.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article was based on real-world experience using AI coding tools on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt; and various client projects. If you have questions or want to share your own setup, feel free to reach out.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>tools</category>
    </item>
    <item>
      <title>Can AI Write Verilog for FPGAs</title>
      <dc:creator>静亭雅苑</dc:creator>
      <pubDate>Wed, 14 Oct 2026 15:25:27 +0000</pubDate>
      <link>https://dev.to/whjin/can-ai-write-verilog-for-fpgas-2lam</link>
      <guid>https://dev.to/whjin/can-ai-write-verilog-for-fpgas-2lam</guid>
      <description>&lt;h1&gt;
  
  
  Can AI Actually Write Verilog for FPGAs? My Real-World Test
&lt;/h1&gt;

&lt;p&gt;As someone who does both full-stack web development and FPGA/Verilog programming, I was curious: can AI coding assistants handle hardware description languages?&lt;/p&gt;

&lt;p&gt;Everyone's talking about AI writing JavaScript, Python, and Rust. But what about Verilog? VHDL? Can an LLM actually understand hardware parallelism, timing constraints, and FPGA-specific quirks?&lt;/p&gt;

&lt;p&gt;I decided to put it to the test. Over the past month, I've been using AI tools (Claude, GPT-4, Cursor) on real FPGA projects. Here's what worked, what didn't, and whether AI is actually useful for hardware design.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I Was Skeptical
&lt;/h2&gt;

&lt;p&gt;I'm a self-taught FPGA developer. I know Verilog well enough to design working circuits, but I'm not a seasoned ASIC engineer. So I was hopeful that AI could help — but also skeptical.&lt;/p&gt;

&lt;p&gt;Hardware description languages are fundamentally different from software:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Parallel execution&lt;/strong&gt;: Everything happens at once, not step by step&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timing matters&lt;/strong&gt;: A bug that only shows up at 100MHz might be invisible in simulation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource constraints&lt;/strong&gt;: FPGAs have fixed LUTs, flip-flops, and DSP blocks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Toolchain quirks&lt;/strong&gt;: Every FPGA vendor (Xilinx, Intel, Lattice) has its own weirdness&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Could an LLM actually grok this?&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 1: Basic Modules
&lt;/h2&gt;

&lt;p&gt;Let's start simple. I asked Claude to write a UART transmitter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "Write a Verilog module for a UART transmitter, 115200 baud, 8N1, 50MHz clock."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It wrote a clean, well-structured UART transmitter. It had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A baud rate generator&lt;/li&gt;
&lt;li&gt;A shift register&lt;/li&gt;
&lt;li&gt;Start/stop bit logic&lt;/li&gt;
&lt;li&gt;Even added a parity bit option&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Was it correct? Mostly. I had to tweak the baud rate divisor calculation (it used 50MHz / 115200 ≈ 434, which is right), but the structure was solid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ✅ Works well for standard building blocks. UART, SPI, I2C, PWM — all the common interfaces.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 2: State Machines
&lt;/h2&gt;

&lt;p&gt;Next, I asked for a more complex design: a SPI master with a configurable register file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "Write a Verilog SPI master module that can read/write to internal registers, 4-wire SPI, mode 0."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: The output was good. It had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proper SPI mode 0 timing (CPOL=0, CPHA=0)&lt;/li&gt;
&lt;li&gt;A state machine for the SPI transaction&lt;/li&gt;
&lt;li&gt;An internal register bank&lt;/li&gt;
&lt;li&gt;Chip select handling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One thing it got wrong: it used a blocking assignment (&lt;code&gt;=&lt;/code&gt;) in a sequential block where it should have used non-blocking (&lt;code&gt;&amp;lt;=&lt;/code&gt;). This is a classic Verilog gotcha — the kind of thing that simulation might not catch, but synthesis will hate.&lt;/p&gt;

&lt;p&gt;I caught it because I know what to look for. A beginner might not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ⚠️ Good structure, but watch for subtle Verilog mistakes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 3: Timing and Constraints
&lt;/h2&gt;

&lt;p&gt;Here's where things get interesting. Timing closure is one of the hardest parts of FPGA design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "My design has a 100MHz clock and I'm getting setup time violations. How do I fix this?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It gave the standard advice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add pipeline registers&lt;/li&gt;
&lt;li&gt;Retime logic&lt;/li&gt;
&lt;li&gt;Use FPGA's built-in RAM blocks&lt;/li&gt;
&lt;li&gt;Check for combinational loops&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All good advice — but generic. It couldn't actually look at my specific timing report and tell me which path was the problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ⚠️ Good theoretical advice, but can't analyze your specific timing report.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 4: Debugging Existing Code
&lt;/h2&gt;

&lt;p&gt;This is where I was most curious. Can AI help debug broken Verilog?&lt;/p&gt;

&lt;p&gt;I took a working SPI module and introduced a bug: I swapped the MOSI and MISO signals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "My SPI receiver isn't working. The data I'm getting is all zeros. Here's my code: [pasted Verilog]"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It read through the code, spotted the MISO/MOSI mix-up within seconds. It explained why it was wrong and how to fix it.&lt;/p&gt;

&lt;p&gt;Impressive. But let's be honest — this was a simple bug. What about trickier ones?&lt;/p&gt;

&lt;p&gt;I tried a more subtle bug: a metastability issue where I forgot to double-synchronize an asynchronous input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "I'm getting random bit errors on my UART RX line. The design works in simulation but fails on hardware."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It suggested checking for metastability issues. It mentioned that asynchronous inputs need proper synchronization. But it didn't pinpoint the exact issue because it couldn't see my full design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ✅ Great for spotting obvious bugs. ⚠️ Harder for subtle timing/metastability issues.&lt;/p&gt;




&lt;h2&gt;
  
  
  Test 5: FPGA-Specific Knowledge
&lt;/h2&gt;

&lt;p&gt;What about FPGA vendor-specific stuff? Like Xilinx UltraRAM, or Intel DSP blocks?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt&lt;/strong&gt;: "Write a Verilog design that uses a Xilinx DSP48E2 block to implement a FIR filter."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It wrote the structure, but the DSP48E2 instantiation was wrong. It used generic names instead of the actual Xilinx primitive names.&lt;/p&gt;

&lt;p&gt;You'd need to know the exact primitive names, ports, and parameters — which AI doesn't always get right.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: ⚠️ Good for generic logic, but vendor-specific primitives need manual correction.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Actually Saves Me Time
&lt;/h2&gt;

&lt;p&gt;After a month of using AI on FPGA projects, here's what actually saves time:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Boilerplate and Common Interfaces
&lt;/h3&gt;

&lt;p&gt;UART, SPI, I2C, PWM, I2S — all the standard building blocks. AI writes these correctly 90% of the time, saving me hours of looking up reference code.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Testbenches
&lt;/h3&gt;

&lt;p&gt;Writing testbenches is tedious. AI is surprisingly good at them. Ask it to "write a testbench for this UART module that sends 0x55 and 0xAA and checks the output" — it does it.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Explaining Existing Code
&lt;/h3&gt;

&lt;p&gt;Staring at someone else's Verilog for hours? Paste it into Claude and ask "what does this do?" It's surprisingly good at reverse-engineering.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Debugging Obvious Bugs
&lt;/h3&gt;

&lt;p&gt;Syntax errors, wrong port directions, missing &lt;code&gt;endmodule&lt;/code&gt; — AI catches these instantly.&lt;/p&gt;




&lt;h2&gt;
  
  
  What AI Still Sucks At
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Timing Closure
&lt;/h3&gt;

&lt;p&gt;This is the hard part of FPGA design. AI can't read your timing report and tell you exactly which path to fix. You still need to understand setup/hold time, clock skew, and retiming yourself.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Resource Optimization
&lt;/h3&gt;

&lt;p&gt;"Can I fit this design into a Lattice iCE40 with 1280 LUTs?" AI can estimate, but it can't actually run synthesis and see the real resource usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Vendor-Specific Tooling
&lt;/h3&gt;

&lt;p&gt;Xilinx Vivado, Intel Quartus, Lattice iCEcube2 — each has its own Tcl scripting, constraints format, and build flow. AI doesn't know the ins and outs of your specific toolchain.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Subtle Hardware Bugs
&lt;/h3&gt;

&lt;p&gt;Metastability, race conditions, glitches — these are the bugs that don't show up in simulation but eat you alive on real hardware. AI won't catch these unless you explicitly point them out.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Workflow Now
&lt;/h2&gt;

&lt;p&gt;Here's how I actually use AI for FPGA work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Design phase&lt;/strong&gt;: I sketch the block diagram myself. AI doesn't make architectural decisions for me.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation&lt;/strong&gt;: I ask AI to write the boilerplate modules (UART, SPI, etc.).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration&lt;/strong&gt;: I wire everything together manually.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testbench&lt;/strong&gt;: AI writes the testbench.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging&lt;/strong&gt;: If simulation fails, I paste the code and ask AI for help.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synthesis&lt;/strong&gt;: I run the tools myself. AI doesn't touch the timing constraints.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;AI is a copilot, not the pilot. It handles the tedious parts, I handle the architecture and the tricky bits.&lt;/p&gt;




&lt;h2&gt;
  
  
  Should FPGA Developers Use AI?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yes, with caveations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI is great for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing standard building blocks&lt;/li&gt;
&lt;li&gt;Generating testbenches&lt;/li&gt;
&lt;li&gt;Debugging obvious bugs&lt;/li&gt;
&lt;li&gt;Explaining unfamiliar code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI is NOT good for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Architectural decisions&lt;/li&gt;
&lt;li&gt;Timing closure&lt;/li&gt;
&lt;li&gt;Vendor-specific optimization&lt;/li&gt;
&lt;li&gt;Subtle hardware bugs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of AI as a junior engineer. It can crank out working code for well-defined tasks, but you still need to review it carefully. And for the hard problems — timing, resources, architecture — you're still the one in charge.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;AI won't replace FPGA engineers anytime soon. Hardware design is too nuanced, too tied to specific hardware, too dependent on real-world measurement.&lt;/p&gt;

&lt;p&gt;But AI will make FPGA developers more productive. The tedious boilerplate that used to take hours? Now it takes minutes. The time saved can go into the hard parts — architecture, optimization, testing — where it actually matters.&lt;/p&gt;

&lt;p&gt;If you're an FPGA developer and you're not using AI yet, you're spending too much time writing UART and SPI modules from scratch.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This was based on real FPGA development work on &lt;a href="https://wuhuajin.com" rel="noopener noreferrer"&gt;wuhuajin.com&lt;/a&gt;. If you're also doing FPGA + software development, I'd love to hear how you're using AI tools.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
