Skip to content

Conversation

@lakshaydewan
Copy link

@lakshaydewan lakshaydewan commented Nov 6, 2024

Improved the lighthouse score on mobile devices by preloading fonts and using Native Script tag from next/script
the FCP of the website went down from 3 seconds average to 1.5 seconds improving the performance greatly.
Screenshot 2024-11-06 at 10 47 30 PM

Summary by CodeRabbit

  • New Features

    • Improved script loading performance with the use of the <Script> component and lazyOnload strategy.
    • Added preloading for the Fira Code font from a CDN.
  • Bug Fixes

    • Corrected a typo in the Google Fonts preconnect link.
  • Chores

    • Removed the import statement for the Fira Code font in the global CSS.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes in this pull request involve modifications to the Next.js application, specifically in how scripts and external resources are managed. The <script> tag for GitHub buttons is replaced with the <Script> component from next/script, utilizing the lazyOnload strategy for deferred loading. Additionally, the document structure is improved with a corrected link for Google Fonts and the addition of a CSS preload for the Fira Code font. An import statement for the Fira Code font is removed from the global CSS file, streamlining resource management.

Changes

File Change Summary
pages/_app.tsx Replaced <script> tag with <Script> component using strategy='lazyOnload'.
pages/_document.tsx Added import for <Script>, corrected preconnet to preconnect, added preload for Fira Code CSS, modified Google Fonts link from stylesheet to preload.
styles/globals.css Removed import statement for Fira Code font.

Possibly related issues

Possibly related PRs

  • fix: fixed dashboard scripts #3304: This PR's changes regarding script handling and external resource management are relevant to the modifications made in the current PR about script loading strategies.

Suggested labels

ready-to-merge, bounty

Suggested reviewers

  • derberg
  • magicmatatjahu
  • Mayaleeeee
  • asyncapi-bot-eve
  • devilkiller-ag
  • sambhavgupta0705
  • anshgoyalevil

Poem

🐇 In the land of code where rabbits play,
Scripts now load in a lazy way.
Fonts are preloaded, errors are few,
Optimized paths for a faster view.
Hopping through changes, we cheer and say,
"Performance improved, hip-hip-hooray!" 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link

netlify bot commented Nov 6, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 1e2f9e4
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/672baaea0cd7fd00087d841a
😎 Deploy Preview https://deploy-preview-3368--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@asyncapi-bot
Copy link
Contributor

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 49
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3368--asyncapi-website.netlify.app/

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
pages/_app.tsx (1)

48-48: Add newline at end of file.

Add a newline character at the end of the file to comply with linting rules.

 export default appWithTranslation(MyApp);
+
🧰 Tools
🪛 eslint

[error] 48-48: Newline required at end of file but not found.

(eol-last)


[error] 48-48: Insert

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2fb1634 and 1e2f9e4.

⛔ Files ignored due to path filters (7)
  • public/img/social/cli-card.jpg is excluded by !**/*.jpg
  • public/img/social/generator-card.jpg is excluded by !**/*.jpg
  • public/img/social/githubactions-card.jpg is excluded by !**/*.jpg
  • public/img/social/meetings.png is excluded by !**/*.png
  • public/img/social/modelina-card.jpg is excluded by !**/*.jpg
  • public/img/social/parsers-card.jpg is excluded by !**/*.jpg
  • public/img/social/website-card.jpg is excluded by !**/*.jpg
📒 Files selected for processing (3)
  • pages/_app.tsx (3 hunks)
  • pages/_document.tsx (2 hunks)
  • styles/globals.css (0 hunks)
💤 Files with no reviewable changes (1)
  • styles/globals.css
🧰 Additional context used
🪛 eslint
pages/_app.tsx

[error] 48-48: Newline required at end of file but not found.

(eol-last)


[error] 48-48: Insert

(prettier/prettier)

pages/_document.tsx

[error] 23-23: Replace "preconnet" with 'preconnet'

(prettier/prettier)


[error] 23-23: Unexpected usage of doublequote.

(jsx-quotes)


[error] 24-24: Replace "preconnect" with 'preconnect'

(prettier/prettier)


[error] 24-24: Unexpected usage of doublequote.

(jsx-quotes)


[error] 26-26: Insert ·

(prettier/prettier)


[error] 28-28: Replace "preload" with 'preload'

(prettier/prettier)


[error] 28-28: Unexpected usage of doublequote.

(jsx-quotes)

🔇 Additional comments (4)
pages/_app.tsx (1)

5-5: LGTM: Proper import of Next.js Script component.

The import is correctly placed and follows Next.js best practices for script management.

pages/_document.tsx (3)

Line range hint 3-12: LGTM: Clean implementation of Document setup

The addition of the Script import and getInitialProps implementation follows Next.js best practices.

🧰 Tools
🪛 eslint

[error] 1-5: Run autofix to sort these imports!

(simple-import-sort/imports)


[error] 7-8: Delete

(prettier/prettier)


[error] 7-8: More than 1 blank line not allowed.

(no-multiple-empty-lines)


26-30: Great performance optimization with font preloading

The switch to preloading fonts is an excellent optimization that aligns with the PR's objective to improve the Lighthouse score. This change will help reduce the First Contentful Paint (FCP) by loading critical fonts earlier in the page lifecycle.

🧰 Tools
🪛 eslint

[error] 26-26: Insert ·

(prettier/prettier)


[error] 28-28: Replace "preload" with 'preload'

(prettier/prettier)


[error] 28-28: Unexpected usage of doublequote.

(jsx-quotes)


37-37: Excellent optimization using Next.js Script component

The replacement of the regular script tag with Next.js's Script component and lazyOnload strategy is a great optimization. This ensures that the GitHub buttons script doesn't block the initial page load, contributing to the improved Lighthouse score.

{/* <MDXProvider components={mdxComponents}> */}
<Head>
<script async defer src='https://buttons.github.io/buttons.js'></script>
<Script async defer src='https://buttons.github.io/buttons.js' strategy='lazyOnload'></Script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Duplicate GitHub button script detected - needs consolidation

The GitHub button script is currently loaded twice:

  • In pages/_app.tsx
  • In pages/_document.tsx

Both instances use the Next.js Script component with lazyOnload strategy, but loading the same script twice is unnecessary and could impact performance. You should:

  • Keep the script in pages/_document.tsx since it's the more appropriate location for global scripts
  • Remove the duplicate script from pages/_app.tsx
🔗 Analysis chain

Excellent performance optimization using Next.js Script component!

The implementation correctly uses the lazyOnload strategy which is ideal for non-critical third-party scripts like GitHub buttons. This change will help improve the First Contentful Paint (FCP) by deferring script loading.

Let's verify if there are other GitHub button scripts that should be updated for consistency:

Consider moving third-party scripts to a dedicated component (e.g., components/ThirdPartyScripts.tsx) to better organize external dependencies. This would make it easier to manage and audit third-party scripts in the future.


Let me check the content of pages/_document.tsx to see if there's a duplicate GitHub button script that needs to be addressed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other potential GitHub button script tags that might need similar optimization
rg -l 'buttons\.github\.io/buttons\.js'

# Search for any remaining basic script tags that could be optimized
ast-grep --pattern 'script[src]'

Length of output: 111


Script:

#!/bin/bash
# Check content of _document.tsx for GitHub button script implementation
rg -A 2 -B 2 'buttons\.github\.io/buttons\.js' pages/_document.tsx

Length of output: 382

Comment on lines +23 to +24
<link rel="preconnet" href='https://fonts.googleapis.com' />
<link rel="preconnect" href='https://fonts.gstatic.com' crossOrigin='anonymous' />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo and formatting issues

There are a few minor issues to address:

  • Line 23: "preconnet" should be "preconnect"
  • Line 26: Missing space before href attribute

Apply this diff to fix the issues:

-          <link rel="preconnet" href='https://fonts.googleapis.com' />
+          <link rel="preconnect" href='https://fonts.googleapis.com' />
-          <link rel='preload'href='https://cdn.jsdelivr.net/gh/tonsky/FiraCode@4/distr/fira_code.css' />
+          <link rel='preload' href='https://cdn.jsdelivr.net/gh/tonsky/FiraCode@4/distr/fira_code.css' />

Also applies to: 26-26

🧰 Tools
🪛 eslint

[error] 23-23: Replace "preconnet" with 'preconnet'

(prettier/prettier)


[error] 23-23: Unexpected usage of doublequote.

(jsx-quotes)


[error] 24-24: Replace "preconnect" with 'preconnect'

(prettier/prettier)


[error] 24-24: Unexpected usage of doublequote.

(jsx-quotes)

@lakshaydewan lakshaydewan deleted the #3356-performance branch November 6, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants