Today I Learned

Best Practices for URLs When Concatenating Domains with Paths

  1. Concatenating Domains with Paths:

    • Domain: Avoid trailing slashes (e.g., "example.com" over "example.com/").
    • Path: Start with a slash (e.g., "/api/endpoint" over "api/endpoint" or "//api/endpoint").
  2. Removing Trailing Slashes:

    • JavaScript Function:
    function removeTrailingSlash(str) {
      return str.endsWith('/') ? str.slice(0, -1) : str;

Following these practices ensures proper URL formatting, avoids issues, and promotes clean and standardized URLs.