Skip to content

Relative URLs? #8

Description

@snej

The spec doesn't mention relative URLs — are they allowed? And if so, what is the base URL they're interpreted relative to?

I recall this coming up as a bit of a compatibility issue in handling RSS/Atom feeds.

(My preference would be to allow them, since they make the feed more compact, and that they should be relative to the home_page_url, since that's likely to be a parent or sibling of where the individual articles' URLs will be. But then there are edge cases like what if there's no home_page_url...)

Activity

  1. manton commented on May 17, 2017

    @manton
    Owner

    We were just discussing this earlier today. I actually wish that all URLs (links and image references) would be absolute URLs, since there's less room for bugs between different feed reader implementations. But it seems difficult to try to enforce that.

    I think you're right that the base URL should be home_page_url. It's strongly recommended to include it. Really all feeds that are on the web should have home_page_url.

  2. donohoe commented on May 17, 2017

    @donohoe

    I would argue for absolute URLs. Relative makes sense if you expect majority of use cases to be by a site creating JSON to use within the same site.

    Once you rely on a JSON feed for syndication, apps, and off-site usage it would likley introduce more problems than it solves (as per @Matons point).

  3. jbafford commented on May 19, 2017

    @jbafford

    I think the spec should allow relative urls, if for no other reason than people are going to use them whether the spec allows it or not.

    In #38, I suggested splitting home_page_url into two fields (site_url and resource_url, with the latter serving the primary stated purpose of home_page_url) for semantic clarity. Following from that, I would propose that:

    • A base url can be specified explicitly with a new base_url field
    • A base url can be specified implicitly from home_page_url or resource_url, if either are present. (Specifically: the site_url proposed in Split home_page_url into two separate fields #38 is not a considered source for this purpose because it is intended to describe a different semantic object.)
    • Parsers should follow the same rules for interpreting paths as the html <base> element.
    • Using paths (absolute or relative) without specifying a base url is a error. This is probably a semantic (not syntactic) error. I have no opinion on how parsers should indicate their displeasure.
  4. voidfiles commented on May 19, 2017

    @voidfiles
    Contributor

    Given that simplicity seems to be key to json feed. It might make sense to have a strict rule for absolute urls.

    The current suggestion is that if a feed is invalid, don't parse it. So, as long as people realize that their feeds are invalid when they use relative urls, and thus won't be parsed. They have a pretty strong incentive to use absolute urls.

  5. glv commented on May 23, 2017

    @glv

    My vote is to require absolute URLs in JSON Feed itself.

    However, relative URLs within content_html fields of items should be allowed, and the spec should be updated to clarify that such URLs should be interpreted relative to that item's url. A great many blogs represent intra-blog links (including image URLs) with relative links.

  6. manton commented on May 23, 2017

    @manton
    Owner

    Just to be clear, any url or _url field should definitely be an absolute URL. The way I interpreted this issue is that it was only about links in content_html. As others have pointed out, while relative URLs are annoying to deal with in a feed reader, it's too much to expect that feed generators will handle this. They'd have to parse a blog post's content and update all the links, <img>, etc. while serving the JSON.

  7. glv commented on May 23, 2017

    @glv

    OK then … so the only question is, should relative URLs in content_html be based on the item's url or on the feed's home_page_url? Does it matter?

  8. glv commented on May 23, 2017

    @glv

    (To be clear … for the typical case of a feed for a blog on a single site, either one should work fine. But what about the case for a feed that aggregates items from multiple sites?)

  9. manton commented on May 23, 2017

    @manton
    Owner

    @glv That's a great point about a feed aggregated from multiple sites. Micro.blog already serves a timeline feed like this that includes multiple users/sites. It would have to be relative to the item's URL in that case.

    Also worth pointing out there are a few variations of relative URLs. It would greatly simplify feed readers if they could depend on relative URLs starting with /, and so easily constructed from the item URL or home page hostname. Again, I'm torn on making any of this a requirement, but it would be nice. (Blog systems with links that don't start with / are unlikely to work anyway across archive or category pages.)

  10. snej commented on May 24, 2017

    @snej
    Author

    The case for relative URLs is that the code generating the feed may not know the details of the exact hostname/port the site is being served from, especially if the server is behind a proxy. And in general CS principles, it seems like a good approach to keep the code for a single page from having to know higher-level details like this. All the feed generator should really need to know is where its JSON file and the articles appear relative to each other.

    As a user of various CMSs over time, I find it annoying when a working site breaks just because I moved it from a staging server to a real server, or because I put it under a path instead of at the root.

  11. sjehuda commented on Oct 21, 2025

    @sjehuda

    This is related to proposal #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions