<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Client Side Re｜林鼎淵 Dean Lin</title>
    <link>https://deanlin.net/tags/client-side-re/</link>
    <image><url>https://deanlin.net/images/author_hu_aa256fc934e9a932.jpg</url><title>Client Side Re｜林鼎淵 Dean Lin</title><link>https://deanlin.net/tags/client-side-re/</link><width>144</width><height>144</height></image>
    <description>林鼎淵（Dean Lin）的部落格：生成式 AI 企業內訓講師、外商資安公司軟體專家、7 本書作者。400 多篇文章用白話分享生成式 AI 實戰、Claude Code 與 Vibe Coding 教學、團隊合作與職場成長。</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <copyright>© 2020–2026 林鼎淵 Dean Lin</copyright>
    <lastBuildDate>Thu, 18 Mar 2021 12:36:01 +0800</lastBuildDate>
    <atom:link href="https://deanlin.net/tags/client-side-re/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>SSR、CSR名詞理解 &amp; 應用場景</title>
      <link>https://deanlin.net/blog/202103/ssr-vs-csr/</link>
      <pubDate>Thu, 18 Mar 2021 12:36:01 +0800</pubDate>
      <guid>https://deanlin.net/blog/202103/ssr-vs-csr/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>技術教學</category>
      <description>當老闆或是主管問你為什麼選擇這個技術時，如果支支吾吾打不出來就遜掉了；理解為什麼該這樣做才是對技術的負責。</description>
      <media:content url="https://deanlin.net/blog/202103/ssr-vs-csr/images/ssr-vs-csr-og_hu_e797feeb9e8b0924.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<p>當老闆或是主管問你為什麼選擇這個技術時，如果支支吾吾打不出來就遜掉了；理解為什麼該這樣做才是對技術的負責。</p>
<p><img src="https://deanlin.net/blog/202103/ssr-vs-csr/images/ssr-vs-csr-01.webp" width="1400" height="785" alt="SSR、CSR名詞理解 &amp; 應用場景（圖 1）" fetchpriority="high" decoding="async"></p>
<pre tabindex="0"><code>CSR - Client-Side Rendering（客戶端渲染）
  ➤ 優點
  ➤ 缺點
  ➤ 應用場景
SSR - Server-Side Rendering（伺服器端渲染）
  ➤ 優點
  ➤ 缺點
  ➤ 應用場景
可以思考的問題
  ➤ 現實面遇到的狀況
  ➤ 運用框架結合 CSR 與 SSR 的優點讓網站取得雙贏
</code></pre><h2 id="csr--client-side-rendering客戶端渲染">CSR — Client-Side Rendering（客戶端渲染）<a class="h-anchor" href="#csr--client-side-rendering%e5%ae%a2%e6%88%b6%e7%ab%af%e6%b8%b2%e6%9f%93" aria-label="這個段落的連結"></a></h2>
<p>渲染過程全部交給 client 的瀏覽器去處理，server 不參與任何渲染。一開始的 HTML 是空白的，需要等待 JS 下載並執行後瀏覽器才會顯示畫面。</p>
<h3 id="-優點">優點：<a class="h-anchor" href="#-%e5%84%aa%e9%bb%9e" aria-label="這個段落的連結"></a></h3>
<ul>
<li><strong>減少 server 端的壓力</strong>：因為 JS 及 CSS 在第一次都已經發送到 client 端，之後只需要向 server 端取得相關頁面的 data 即可</li>
<li><strong>頁面切換速度快</strong>：因為 HTML 頁面都是 client 端自己編譯的，所以頁面切換時不需要像 SSR 等待 server 回傳 HTML；而且網頁內容的改變通常都是局部的，這樣就避免了不必要的跳轉及重複渲染。</li>
</ul>
<h3 id="-缺點">缺點：<a class="h-anchor" href="#-%e7%bc%ba%e9%bb%9e" aria-label="這個段落的連結"></a></h3>
<ul>
<li><strong>首屏顯示慢</strong>：明明首頁只有一點內容卻把下載了所有頁面的資源</li>
<li><em>SEO 較差</em>：因一開始的 HTML 是空白的，雖然現在 Google 的爬蟲也會等 javascript 編譯好再爬，但這塊對 SEO 的實際幫助還需要時間驗證</li>
</ul>
<h3 id="-應用場景">應用場景：<a class="h-anchor" href="#-%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af" aria-label="這個段落的連結"></a></h3>
<ul>
<li><strong>會高頻操作且不需 SEO 的網站</strong>：像是內部管理系統，如果這類型的系統採取 SSR 會造成 server 端很大的負荷。</li>
</ul>
<hr>
<h2 id="ssr--server-side-rendering伺服器端渲染">SSR — Server-Side Rendering（伺服器端渲染）<a class="h-anchor" href="#ssr--server-side-rendering%e4%bc%ba%e6%9c%8d%e5%99%a8%e7%ab%af%e6%b8%b2%e6%9f%93" aria-label="這個段落的連結"></a></h2>
<p>HTML 由 server 編譯出來返回 client 端，所以 client 看到的畫面就是最終版 HTML。</p>
<h3 id="-優點-1">優點：<a class="h-anchor" href="#-%e5%84%aa%e9%bb%9e-1" aria-label="這個段落的連結"></a></h3>
<ul>
<li><strong>SEO 排名更高</strong>：因為 Google 爬蟲可以直接抓到網站的資訊</li>
<li><strong>首屏渲染快</strong>：因為不需要下載一堆 JS 以及 CSS 執行後才看到頁面</li>
<li><strong>減少 client 端的耗電量</strong>：因為編譯的步驟都在 server 端執行</li>
</ul>
<h3 id="-缺點-1">缺點：<a class="h-anchor" href="#-%e7%bc%ba%e9%bb%9e-1" aria-label="這個段落的連結"></a></h3>
<ul>
<li><strong>server 端承受比較大的壓力</strong>：由於頁面都是在 server 端進行編譯，在高併發場景中會消耗相當大的資源</li>
</ul>
<h3 id="-應用場景-1">應用場景：<a class="h-anchor" href="#-%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-1" aria-label="這個段落的連結"></a></h3>
<ul>
<li><strong>低頻操作但需要 SEO 優化的網站</strong>：像是媒體類型的網站，因為文章需要被搜尋到，我們看一篇文章也需要一點時間很少高頻的操作這個網站</li>
</ul>
<hr>
<h2 id="可以思考的問題">可以思考的問題<a class="h-anchor" href="#%e5%8f%af%e4%bb%a5%e6%80%9d%e8%80%83%e7%9a%84%e5%95%8f%e9%a1%8c" aria-label="這個段落的連結"></a></h2>
<h3 id="-現實面遇到的狀況">現實面遇到的狀況<a class="h-anchor" href="#-%e7%8f%be%e5%af%a6%e9%9d%a2%e9%81%87%e5%88%b0%e7%9a%84%e7%8b%80%e6%b3%81" aria-label="這個段落的連結"></a></h3>
<p>在 CSR 的狀況下如果某個頁面需要同時存取多個 api，假設 client 端的網速不理想，那使用者的體驗會極差；在這種情況下 SSR 會因為 server 環境相對穩定而獲得相對好的使用者體驗。</p>
<h3 id="-運用框架結合-csr-與-ssr-的優點讓網站取得雙贏">運用框架結合 CSR 與 SSR 的優點讓網站取得雙贏<a class="h-anchor" href="#-%e9%81%8b%e7%94%a8%e6%a1%86%e6%9e%b6%e7%b5%90%e5%90%88-csr-%e8%88%87-ssr-%e7%9a%84%e5%84%aa%e9%bb%9e%e8%ae%93%e7%b6%b2%e7%ab%99%e5%8f%96%e5%be%97%e9%9b%99%e8%b4%8f" aria-label="這個段落的連結"></a></h3>
<p>經由上面的分析，我想大家應該已經感受到 CSR 與 SSR 可以說是性質完全相反的渲染了，所以實際應用上我們通常會讓第一個頁面用 SSR 來爭取更高的 SEO，其他的頁面則採用 CSR 的方式來操作給使用者兩好的體驗。</p>
<p>現有的框架： <code>Nuxt.js</code>（Vue）、<code>Next.js</code>（React）都有很好的解決方案</p>
<hr>
<blockquote class="pullquote"><p>以上是我個人針對 SSR、CSR 技術的理解，如果有理解錯誤的地方希望有大神給予指教，感恩不盡～</p>
</blockquote>
]]></content:encoded>
    </item>
  </channel>
</rss>
