JSDC
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    # Web fundamentals for performant web apps - Dhrubajit Chowdhury {%hackmd @JSDC2024/INuUpOqWS42gD1_pz5S4Bg %} Slido:https://app.sli.do/event/xvVZvXjWEa753zmah5mSxQ > 開始做筆記 ## About Me - Ascenda [McMasted-Carr](https://www.mcmaster.com/) - Old but fastest XD ## Why Performance Matters? ### Need to Educate - UX + Retension - ![image](https://hackmd.io/_uploads/SyK-_imSJe.png) ### Conversion Rate - ![image](https://hackmd.io/_uploads/SkzXdsmHke.png) ### SEO rankings - ![image](https://hackmd.io/_uploads/rydSusQrkg.png) ### Greater Reach - ![截圖 2024-12-21 上午10.30.43](https://hackmd.io/_uploads/HJiwdiQB1x.png) ### Critical Rendering Path At a high level, your browser's rendering engine performs the following step: - Fetch HTML, CSS, JS (resource fetching) - Create Render tree (DOM + CSSOM) - Generate layout - Paint the content to the browser ## what is considered good performance? - ![截圖 2024-12-21 上午10.31.04](https://hackmd.io/_uploads/SyIc_iXryg.png) - [Core Web Vitals](https://web.dev/articles/vitals?hl=zh-tw) - Largest Contentful Paint (LCP) - Interaction to Next Paint (INP) - Cumulative Layout Shift (CLS) - Accumulative layout shift - Summary - ![image](https://hackmd.io/_uploads/H1WetoQHyg.png) ## What is our goal today? - Reduce Network Payload - Higher Level - ![image](https://hackmd.io/_uploads/By0SFsXrye.png) ## Resource Fetching - ![image](https://hackmd.io/_uploads/B1l2KoXB1g.png) - prefetch ![截圖 2024-12-21 上午10.44.55](https://hackmd.io/_uploads/HyF6ooXSyx.png) - defer - async - ![截圖 2024-12-21 上午10.37.37](https://hackmd.io/_uploads/B1HW9s7r1l.png) - preload: Preloads critical resources needed for the page to render, improving performance by fetching them early. - prefetch: Downloads resources that are likely to be needed soon, typically for subsequent navigation or user actions. Has low priority. - preload(預加載) 這是一個高優先級的資源加載策略,主要用於載入當前頁面渲染時必需的關鍵資源。比如說: - 頁面的主要 CSS 文件 - 關鍵的字體文件 - 頁面頂部的大圖 - prefetch(預獲取) 這是一個低優先級的資源加載策略,瀏覽器會在空閒時間才去下載這些資源。適用於: - 下一頁可能會用到的資源 - 用戶很可能點擊的頁面 - 其他非關鍵資源 ### 主要區別: - 優先級:preload 是高優先級,prefetch 是低優先級 - 時機:preload 會立即下載,prefetch 會在瀏覽器空閒時才下載 - 用途:preload 用於當前頁面必需資源,prefetch 用於預測性的加載可能需要的資源 ### 效能影響: - 正確使用 preload 可以大幅提升當前頁面的加載速度 - 合理使用 prefetch 可以提升後續頁面的訪問體驗 - 但過度使用都會造成不必要的網路頻寬消耗,需要謹慎評估 ## preventing layout shift Loading Skeleton + placeholders ![截圖 2024-12-21 上午10.40.05](https://hackmd.io/_uploads/r1AT5iXH1g.png) ```jsx <Suspence fallback={<Skeleton>}> <Content /> </Suspence> ``` - Ant Design ## Reduce payload ## Lazying load images ![image](https://hackmd.io/_uploads/S1uZjjXryg.png) - LQIP native browser support ```html <img loading="lazy" > <img src="a.jpg" data-src="b.jpg" > ``` ### Native browser support lazy loading ```html <img alt="A typing cat" src="cat.jpg" loading="lazy" width="400" height="400"> ``` ## optimizing images ### Use CDN image optimisation example ![image](https://hackmd.io/_uploads/HJqriimHJg.png) ```bash ...cat.jpg?q=50&h=500 ``` 1. **CDN 圖片參數說明** - `q=50`:設定圖片品質為 50% - `h=500`:設定圖片高度為 500px,寬度會自動等比例調整 2. **CDN 圖片優化的好處** - 自動壓縮和優化圖片 - 依據裝置提供最適合的圖片大小 - 支援現代圖片格式(如 WebP、AVIF) - 全球分散式快取,加快載入速度 - 節省原始伺服器頻寬 Popular image CDNs: Akamai | cloudinary | cloudflare images | imgix ## Key Takeaways ![image](https://hackmd.io/_uploads/B1YjojQSJe.png) ## 總結: 1. **數據驅動的決策** - 以實際數據支持優化策略的重要性 2. **資源預載入優化** ```html <link rel="preload" as="font" /> ``` - 優化關鍵渲染路徑 - 提前載入重要資源 3. **元件lazy loading** ```jsx lazy(() => import('./LargeComponent')) ``` - 非即時需要的元件延遲載入 4. **資源lazy loading** ```html <img alt="A typing cat" src="cat.jpg" loading="lazy" width="400" height="400" /> ``` - 圖片和其他資源延遲載入 - 避免不必要的資源載入 5. **CDN 圖片優化** - 使用 CDN 服務優化圖片 - 自動調整圖片大小和品質 - 全球分散式快取 6. **Skeleton優化** - 使用Skeleton載入器 - 減少版面位移(Layout Shift) - 提升使用者體驗 ## Q & A 1. Would you typically take performance optimization into account during the development phase, or do you prefer only after noticeable issues arise post-launch? > 2. What observation tools you usually used for performance? > I usually use chrome DevTools (Performance Tab for profiling, Network Tab for load times) and React devtools since I am primarily working with react. 3. How would you optimize images in the context of responsive web design (RWD)? > You can use the <picture> element or use the srcset attr to serve different images to different screen sizes. <img src="default-image.jpg" srcset="image-480w.jpg 480w, image-800w.jpg 800w" sizes="(max-width: 768px) 100vw, 800px" alt="Responsive Image" /> >Or <picture> <source srcset="image-large.webp" media="(min-width: 1024px)"> <source srcset="image-medium.webp" media="(min-width: 768px)"> <img src="image-small.webp" alt="Responsive Image"> </picture> > This blog post goes in depth to explain this technique https://web.dev/learn/design/responsive-images#srcset 4. Great presentation! any suggestions for Image optimization except CDN? > Make sure you are compressing your images using gZip/Brotli and use modern web image formats like .webp 5. Do you have experience with API response cache in Frontend side? > 6. Do you have any tips to reduce the size and loading time of your GeoJSON data for web map? > Unfortunately, I do not have much experience on working with geojson data, but you can try using various tools to simplify the polygons and lines on the data. Perhaps something like turf.js. Make sure to use compression techniques on the server before network transmissions. 7. Do you actually get the growth in conversion rate after deploying these performance optimisation? I find it hard to convince the boss about the performance? > Yes you definitely do. You can start by tracking user analytics and their behavior across your app. Make minor optimizations. See the change. With this data you can then ask your stakeholder to invest more on performance. 8. CLS is not easy to fix because our images are all user-generated. We don't know the height of the image so we also need backend resource to parse the image? > This is indeed challenging. In such situations, easy approach is to add a default aspect-ratio which the majority of the images might have. Having loading skeletons with a rough estimation of the image dimension is also good. > For a more involved approach, when user generated images are stored on the database, u can also store meta information of the image in the table (such as width, height). During rendering on the client side, u can use these dimensions to set up placeholder. 9. What is differences between frontend cache and backend cache? > Frontend cache usually refers to the cache on the client side (the browser). This means the data is stored on the user's device (desktop, tablet, mobile, etc). Caching using local storage, cookies, session storage, caching on a service worker. This article goes in depth to how you can use a frontend cache effectively, https://web.dev/learn/pwa/caching. > A backend cache refers to the storage on your server. Depending on the context, this may be a CDN, an in-memory storage like mamcache or redis, static files on the server. ## 聊天區 >

    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