Wells Liu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # CDN 簡介 ## 先講結論: CDN 提供了一個可以從不同伺服器下載需求檔案的服務, 因此... 1. 妥善的引入CDN 可以讓你減少你的伺服器流量 2. 由於CDN 無法代管你的Web App 內容, 所以通常用在代管靜態內容上 (例如: css, js, 圖片, 影片.. 等等) 3. 常見的引入方式長得像: ```html= <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"> </head> ``` 4. 通常引入CSS框架或是JS框架會使用CDN來節省流量(熱門框架通常會提供免費的CDN 給大家使用) 5. 像是AWS, GCP, CloudFlare 也有提供免費的CDN 給大家客製使用(當然, 流量有限) ## 什麼是CDN? >[CloudFlare - 什麼是 CDN?](https://www.cloudflare.com/zh-tw/learning/cdn/what-is-a-cdn/) > 內容傳遞網路 Content Delivery Network(CDN) 是指一組分佈在不同地理位置的伺服器,協同工作以提供網際網路內容的快速交付。 > > CDN 允許快速傳輸載入網際網路內容所需的資源,包括 HTML 頁面、javascript 檔、樣式表、圖像和視訊。 CDN 服務已得到不斷普及。如今,大多數 web 流量都通過 CDN 提供服務,包括來自Facebook、Netflix 和亞馬遜等主要網站的流量。 ## 使用CDN 有什麼優點? > 雖然使用 CDN 的優點取決於網際網路設備的大小和需求,但對於大部分的使用者而言,主要優點可分為 4 個不同部分: > > 1. 改善網站載入時間 - 通過將內容分發到訪問者附近的 CDN 伺服器(以及其他優化措施),訪問者體驗到更快的頁面載入時間。由於訪客更傾向離開載入速度慢的網站,CDN 可以減少退回率並增加人們在網站上花費的時間長度。換言之,網站速度越快,使用者停留的時間越長。 > 2. 減少頻寬成本 - 網站代管的頻寬取用成本是網站的主要費用。透過快取和其他最佳化,CDN 可以降低來源伺服器必須提供的資料量,藉此減少網站擁有者的代管成本。 > 3. 增加內容可用性和備援 - 大量流量或硬體故障會中斷正常網站運作。由於 CDN 的分佈性質,CDN 可以處理更多流量,且對於硬體故障的承受情況也比許多來源伺服器更好。 > 4. 改善網站安全性 - CDN 可提供 DDoS 防護、改善安全性憑證及其他最佳化,以改善安全性。 ## CDN 如何減少流量成本? ### 懶人包: 1. 載入的流量是由其他伺服器分擔 2. 使用CDN 載入的檔案會被瀏覽器快取(cache) 3. 被瀏覽器快取(cache)的檔案, 會在使用者需要的時候重複被直接拿出來用 4. 直接拿出來用就不會再對CDN 節點發出要求而重新下載了 >[CloudFlare - 如何使用 CDN 減少頻寬成本?](https://www.cloudflare.com/zh-tw/learning/cdn/how-cdns-reduce-bandwidth-cost/) > 內容傳遞網路 (CDN) 減少了傳輸資料的成本,因為它位於使用者和網站的託管伺服器或原始伺服器之間,從而減少了託管伺服器與網際網路其餘部分之間的流量。CDN 是分佈在世界各地的伺服器網路,可將內容儲存在更靠近終端使用者的位置,從而減少延遲。CDN 提供快取的內容,因此原始伺服器不必一遍又一遍地傳遞相同的內容。 ## CDN 的緩存流程: ### 簡易的流程圖: 用戶 => DNS => DNS給用戶CDN節點IP => 用戶訪問CDN節點 => CDN返回內容給客戶(結束) / CDN向server請求內容 => CDN判斷是否快取內容 => 返回內容給用戶 => 結束 ### 詳細內容: 1. 用戶對某網站發出請求 用戶對網站發出請求後,DNS 解析用戶請求的網站域名,並且回覆一 IP 位址(節點的 IP 位址)。 2. 獲得網站的 IP 位址(CDN 的 IP 位址) DNS 告知用戶該網站的 IP 位址(實際上是節點的 IP 位址)後,用戶將會請求 DNS 給的 IP,讓請求知道要去哪個地方。 3. CDN 節點上的緩存回應用戶請求 請求到了節點後,節點確認當前請求的內容是否已經緩存在節點上。 若有: 將節點緩存的內容回應給用戶,流程結束。 若沒有:向源伺服器請求該物件,得到響應後,節點判斷是否要進行緩存後,回應給客戶,流程結束。 CDN 架構與運作方式為藉由遍佈全球的節點,縮短內容與用戶的距離。 ## 為什麼有免費的CDN 可用? ### 懶人包: 1. AWS, GCP, CloudFlare.. 等等, 提供你免費使用CDN, 當你用量大了, 自然會比較傾向購買他們的服務 2. 他們CDN 的節點已經設置了, 流量空著也是空著, 提供你小流量的使用其實也只是邊際成本而已 參考資料: [为什么一些大公司愿意无偿提供CDN服务?](https://www.zhihu.com/question/54200139)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully