Skip to content

Enhance Performance with Optimizations and Lighthouse Audit in Workflow #Issue 2550 #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

HarshSharma0801
Copy link

@HarshSharma0801 HarshSharma0801 commented Feb 25, 2025

Summary

This PR introduces a suite of performance enhancements to the Next.js blog website, addressing render-blocking resources, slow server response times, CSR overhead, and adding a Lighthouse audit to the CI/CD workflow for continuous monitoring. These changes improve Largest Contentful Paint (LCP), Time to First Byte (TTFB), and overall user experience while ensuring stability for long-running processes (e.g., maxDuration: 300).

Fixes -> keploy/keploy#2550

Changes

  1. Render-Blocking Resources:
    ~ Inlined critical CSS for above-the-fold content (e.g., titles, buttons) in pages like Index.tsx, /technology/[slug].tsx, etc.,
    reducing LCP.
    ~ Added for key images (e.g., hero images, HOME_OG_IMAGE_URL) across pages.
    ~ Deferred non-critical scripts by keeping components like PostBody as dynamic imports with next/dynamic.

  2. Slow Server Response Time:
    ~ Optimized API functions in lib/api.ts:
    Added in-memory caching with a 5-minute TTL to fetchAPI.
    Reduced batch sizes (e.g., first: 50 to first: 10) and capped data fetches (e.g., maxPosts: 50) in
    getAllPostsForTechnology, getAllPostsForCommunity, etc.
    Used Promise.all for concurrent API calls in getStaticProps (e.g., /technology/[slug].tsx, /community/[slug].tsx).
    ~ Increased ISR revalidate from 10s to 300s (5 minutes) or 3600s (1 hour) across pages for better caching.

  3. Client-Side Rendering (CSR) Overhead:
    ~ Minimized CSR by leveraging SSG via getStaticProps across all pages (e.g., Index.tsx, /tag/[slug].tsx).
    ~ Simplified client-side logic (e.g., moved content parsing out of useEffect in /community/[slug].tsx).
    ~ Used fallback: "blocking" in getStaticPaths (e.g., /authors/[slug].tsx) to avoid CSR fallbacks.

  4. Lighthouse Audit in Workflow:
    ~ Updated .github/workflows/build-and-deploy.yml:
    Added steps to install @lhci/[email protected], run lhci autorun, and upload reports as lighthouse-report artifacts.
    ~ Created .lighthouseci/lighthouserc.json:
    Audits http://localhost:3000/ with 3 runs, focusing on performance.
    Sets thresholds: LCP < 2.5s, FCP < 1.8s, TBT < 200ms, Speed Index < 4.3s (warnings only).
    Uses filesystem storage due to lack of secret access in this open-source repo.
    ~ Added continue-on-error: true to prevent workflow failure on performance warnings

Testing

~ Locally tested via npm run build and page loads to verify LCP/TTFB improvements.
~ Ran lhci autorun manually to confirm audit functionality and artifact generation.
~ Workflow tested in fork (HarshSharma0801/blog-website) to ensure compatibility.

@HarshSharma0801 HarshSharma0801 force-pushed the harsh-sharma/feat/issue-2550 branch 2 times, most recently from 61706d5 to 56205a0 Compare February 25, 2025 02:14
@HarshSharma0801 HarshSharma0801 changed the title Issue 2550 Enhance Performance with Optimizations and Lighthouse Audit in Workflow #Issue 2550 Feb 25, 2025
@Hermione2408
Copy link
Member

Hey @HarshSharma0801 Thanks for creating the PR, please sign off the DCO and fix the build!

@HarshSharma0801 HarshSharma0801 force-pushed the harsh-sharma/feat/issue-2550 branch from f68a2f7 to f5b59cc Compare March 9, 2025 17:35
@HarshSharma0801
Copy link
Author

@Hermione2408 I have signed DCO and fixed the build , its some version error but fixed it now

@manasmanohar
Copy link
Contributor

Kindly attach the before and after lighthouse and build report.

@HarshSharma0801 HarshSharma0801 force-pushed the harsh-sharma/feat/issue-2550 branch from dd98a80 to 4c76044 Compare March 12, 2025 19:47
@HarshSharma0801
Copy link
Author

@manasmanohar i have attached the lighthouse audit report workflow it runs smoothly , locally !

Screenshot 2025-03-13 at 1 20 42 AM

@HarshSharma0801
Copy link
Author

I think its ready you can also run audits if you want

@HarshSharma0801
Copy link
Author

@manasmanohar Please Approve The changes if reviewed 👍

@Aditya-eddy
Copy link
Member

Aditya-eddy commented Mar 17, 2025

hey @HarshSharma0801 have reviewed some of your changes:
Also the UI in the pr and current pr have some differences can please address them
Current:
Screenshot from 2025-03-17 08-58-56
Screenshot from 2025-03-17 08-58-22

UI pr's:
Screenshot from 2025-03-17 08-58-37
Screenshot from 2025-03-17 08-58-13

Also the reviewer and author currently have # next to their name can please fix that?
image

@HarshSharma0801
Copy link
Author

HarshSharma0801 commented Mar 17, 2025

@Aditya-eddy Sure will resolve it

@HarshSharma0801
Copy link
Author

@Aditya-eddy let me know if you find any other issues

@HarshSharma0801 HarshSharma0801 force-pushed the harsh-sharma/feat/issue-2550 branch from 4c76044 to 63f4600 Compare March 17, 2025 07:07
@HarshSharma0801
Copy link
Author

@Aditya-eddy @manasmanohar I tried to resolve ui issues , with blog website , it seems api for both prod and local environment is different as code is unchanged in production and my PR related to ui , locally we are getting different response , same is with UI , can you please check it

@HarshSharma0801 HarshSharma0801 force-pushed the harsh-sharma/feat/issue-2550 branch from c84abbb to 1940fde Compare March 22, 2025 16:22
@HarshSharma0801
Copy link
Author

@Aditya-eddy @Hermione2408 resolved the UI issues
Screenshot 2025-03-22 at 9 52 48 PM
Screenshot 2025-03-22 at 9 53 16 PM

@HarshSharma0801 HarshSharma0801 force-pushed the harsh-sharma/feat/issue-2550 branch from 1940fde to 9a996f3 Compare March 22, 2025 16:26
…ine CSS and cahing in apis

Signed-off-by: Harsh Sharma <[email protected]>

Signed-off-by: HarshSharma0801 <[email protected]>
Signed-off-by: Harsh Sharma <[email protected]>

Signed-off-by: HarshSharma0801 <[email protected]>
Signed-off-by: HarshSharma0801 <[email protected]>
Signed-off-by: HarshSharma0801 <[email protected]>
Signed-off-by: HarshSharma0801 <[email protected]>
Signed-off-by: HarshSharma0801 <[email protected]>
Signed-off-by: HarshSharma0801 <[email protected]>
@HarshSharma0801 HarshSharma0801 force-pushed the harsh-sharma/feat/issue-2550 branch from 9a996f3 to 1a149b7 Compare March 22, 2025 16:45
@Aditya-eddy
Copy link
Member

Hey @HarshSharma0801
this is the current Lighthouse score:
Screenshot from 2025-03-24 15-48-36
this is the pr's lighthouse score:
Screenshot from 2025-03-24 15-48-47

Maybe some changes have decreased the performance? UI changes looks good.

@TvisharajiK
Copy link
Contributor

Hey @HarshSharma0801 Any updates on this?

Copy link

keploy bot commented Apr 15, 2025

Nice Pr 😄. We currently support Unit Test Generation only for Go projects.
Stay tuned – support for more languages is coming soon! 🚀

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.

5 participants