Skip to content

fix: optimize client redirection and normalize trailing slashes - #1572

Open
Himarghya wants to merge 1 commit into
freeCodeCamp:mainfrom
Himarghya:fix/redirect-efficiency-and-normalization
Open

Himarghya wants to merge 1 commit into
freeCodeCamp:mainfrom
Himarghya:fix/redirect-efficiency-and-normalization

Conversation

@Himarghya

Copy link
Copy Markdown

Checklist:

Description

This PR introduces several performance and routing reliability improvements across client navigation and legacy redirection:

  1. Immediate Landing Redirect: Removed the redundant DOMContentLoaded event listener on index.astro. Since window.location.hash and window.location.replace are available immediately upon script evaluation, executing synchronously speeds up page redirection and prevents potential race conditions if the event already completed.
  2. Slash Normalization: Enhanced getRedirectedPath to sanitize leading/trailing slashes on legacy hash paths to prevent malformed double-slash URLs (e.g. //path// or //path//#id).
  3. Canonical Link in SiteTitle: Updated header home link in SiteTitle.astro to /intro/ (with trailing slash) to match site configuration and prevent unnecessary HTTP 301 redirect hops when clicking the logo.
  4. Test Suite Expansion: Added unit tests covering trailing slash and edge cases for getRedirectedPath.

Verification

  • pnpm test: All 132 tests passed across 7 test suites
  • pnpm lint: Zero lint or formatting errors
  • pnpm build: Static build generated all 40 routes successfully

@Himarghya
Himarghya requested a review from a team as a code owner October 7, 2026 10:21

This branch has not been deployed

No deployments
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.

1 participant