RZ-Huang
    • 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

      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.
      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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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

    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.
    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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # SPA(Single Page Application) ###### tags: `web`、`concept` ## 請簡單解釋什麼是 Single Page Application SPA,單頁式應用,顧名思義就是網頁操作起來很像只有一個頁面而已,它不同於 MPA(Mutiple Page Application),因為不會跳轉畫面的關係,使用者在操作頁面的時候不會看到短暫的空白畫面(等待 Server response),更細微的來說,使用 SPA 會讓使用者覺得很像在操作一個 App 的那種感覺。而使用 SPA 最經典的案例是現代上網者幾乎用過的信箱:「Gmail」,在操作 Gmail 的時候 不會看到換頁面的呈現,每個操作都在同個頁面下實行的。 而 SPA 背後的機制仰賴於 Ajax(Asynchronous JavaScript and XML)的使用,藉由 Ajax 的技術,我們可以在非同步下處理資料的回傳,也就是說,頁面的重新渲染取決於 Server 何時 response,然後再由 JavaScript 把畫面重新渲染,在 response 回來之前,頁面照樣能使用並執行其它動作,因為兩者是非同步的。 ## SPA 的優缺點為何 #### 好處 1. 當網頁中有些功能希望設計成不管做什麼動作都不能中斷這個功能,那麼使用 SPA 是非常合適的選擇,比方說音樂播放網站(如 [StreetVoice](https://streetvoice.com/) ),假想使用者在播放器播放音樂的同時,又想去使用網站其它的功能或者是頁面,使用者當然不希望音樂被中斷(奇檬子不佳),因此保持播放器不被中斷可以讓使用者體驗更好。 2. 呈第 1 點的結尾,有些網頁的一些功能雖然未必需要有不換頁的選擇,但如果有,那就會讓使用者體驗更佳,好比說 Facebook ,在動態中播放一則影片下如果頁面繼續往下滑,那麼影片就會縮小到旁邊去,並且繼續播放著,這種功能雖然未必需要有,但是有的情況下,使用者可以一邊看影片(或聽影片聲音)一邊瀏覽其它動態。 3. 讓前後端的職責更分明(前端只管顯示畫面正確,後端只管傳輸資料到位),而且不會因為前端壞掉而影響到後端的資料存取,或是後端發生問題前端頁面無法顯示,頂多功能故障沒辦法使用或是資料空白。 4. 另外因為這樣的前後端分離的寫法,你可以很方便隨時替換前端和後端的程式語言或是框架,只要確定連結前後端之間的 API 格式還是一樣就可以了。 #### 壞處 1. 使用 SPA 的關係會變成進入網頁之前 JavaScript 還沒 render,這樣的情況會使得 HTML 裡面空空如也,SEO 搜尋不到網頁相關資訊(不過強大的 Google 可以爬 JS 檔案)。 2. 如果像 Google 這種就算可以搜尋得到 JS,還得注意的是, SEO 搜尋時機和 JavaScript render 的時機要怎麼拿捏與修正也可能是個問題。 3. 另外使用 SPA 會變成每次都是載一拖拉庫的 JavaScript(包括其它頁面的 template),就算你只想看一個頁面也是全載。 4. 前端會變得很複雜。使用以前的方法後端只要照著不同頁面回傳相對應的畫面,也就是後端在幫忙控制要傳到哪個對應的 controller 而回傳不同的資料,而使用 SPA 之後這件事變成前端這邊要來實作,重點是一個網址要對應到使用者按下不同 URL 時要呈現哪一個畫面,會讓前端這邊的處理複雜許多,再加上每個狀態下的操作對應的輸出內容又是什麼,之間的操作前後順序要確實掌握否則會出現使用者點 A 文章之後又點 B 文章,結果最後跑出了 A 文章的囧境。 ### 參考資料 1. [跟著小明一起搞懂技術名詞:MVC、SPA 與 SSR](https://medium.com/@hulitw/introduction-mvc-spa-and-ssr-545c941669e9) 2. [前後端分離與 SPA](https://blog.techbridge.cc/2017/09/16/frontend-backend-mvc/?source=post_page-----545c941669e9----------------------)

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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