跳到正文
DEV Community· Mritunjoy Mondal·· 2 小時前AI 評分50

開發者常犯的 7 個 SEO 錯誤,以及如何透過程式碼修正

7 SEO Mistakes Developers Make (and How to Fix Them in Code)

AI 導讀

文章列出開發者常犯的 7 個 SEO 錯誤,並提供程式碼修正方法。錯誤包括 robots.txt 阻擋 Google、正式頁面殘留 noindex,以及內容依賴 JavaScript 才載入;建議採用 SSR 或 SSG,並將 Core Web Vitals 目標設為 LCP 低於 2.5s、INP 低於 200ms、CLS 低於 0.1。

正文

You built a fast, clean site. It still doesn't rank. In most audits I run, the problem isn't content. It's small dev decisions that quietly block Google.

Here are the 7 mistakes I see most, with the code to fix each one.

1. Blocking Google in robots.txt

A staging rule gets pushed to production and the whole site disappears from Google.

Bad:

User-agent: *
Disallow: /

Fix:

User-agent: *
Disallow: /admin/
Sitemap: https://yoursite.com/sitemap.xml

Always check yoursite.com/robots.txt after every deploy.

2. Leaving noindex on live pages

Same story, different file. A noindex meta tag from staging survives launch.

<!-- Remove this on production -->
<meta name="robots" content="noindex, nofollow">

Pro tip: control it with an env variable so it can never leak.

const robots = process.env.NODE_ENV === 'production'
  ? 'index, follow'
  : 'noindex, nofollow';

3. Content that only exists after JavaScript runs

If your page is empty until React fetches data, Google may index a blank page or delay indexing for weeks.

Fix:

  • Use SSR or SSG (Next.js, Nuxt, Astro, SvelteKit)
  • At least render title, H1, main text and links on the server
  • Test with Search Console > URL Inspection > View crawled page

4. Missing or duplicate titles

Every page shipping with the same <title>My App</title> is one of the most common issues I find.

Next.js example:

export const metadata = {
  title: 'Local SEO Checklist for Small Businesses',
  description: 'A step by step local SEO checklist to rank in Google Maps.',
  alternates: { canonical: 'https://yoursite.com/local-seo-checklist' },
};

Rules:

  • Unique title per page, under 60 characters
  • Unique description, around 150 characters
  • Self-referencing canonical on every page

5. Using divs and buttons instead of real links

Google follows <a href>. It does not click your buttons.

Bad:

<div onclick="router.push('/pricing')">Pricing</div>

Good:

<a href="/pricing">Pricing</a>

If Google can't follow your navigation, it can't find your pages.

6. Ignoring Core Web Vitals

Speed is a ranking signal and a conversion killer.

Metric Target Common dev fix
LCP Under 2.5s Preload hero image, serve WebP/AVIF
INP Under 200ms Split bundles, defer third party scripts
CLS Under 0.1 Set width and height on images and embeds
<link rel="preload" as="image" href="/hero.webp">
<img src="/hero.webp" width="1200" height="600" alt="Product dashboard">

7. No structured data

Schema helps Google and AI tools like ChatGPT understand who you are and what the page is about.

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "7 SEO Mistakes Developers Make",
  "author": {
    "@type": "Person",
    "name": "Mritunjoy Mondal",
    "url": "https://mritunjoymondal.com/"
  }
}
</script>

Validate it with Google's Rich Results Test before you ship.

Pre-launch SEO checklist

Copy this into your PR template:

  • [ ] robots.txt allows crawling
  • [ ] No noindex on production
  • [ ] Main content renders server side
  • [ ] Unique title, description, canonical per page
  • [ ] Navigation uses real <a href> links
  • [ ] Images have width, height, alt text
  • [ ] XML sitemap live and submitted
  • [ ] Schema validated

Wrapping up

None of these are hard fixes. They're just easy to miss when you're shipping fast. Fix them once, add them to your checklist, and your next launch starts with a clean SEO foundation.

I write more practical guides like this on technical SEO and AI search. If your site is live but not ranking, drop a comment and I'll point out what to check first.


I'm Mritunjoy Mondal, an AI, GEO and Local SEO expert from India.

來源:DEV Community · dev.to