html icon indicating copy to clipboard operation
html copied to clipboard

Proposal: fallback/mirror hrefs

Open rhendric opened this issue 2 years ago • 3 comments

Requested: a way for an HTML author to express that a hyperlinked external resource is available at multiple locations, in case one of them is unreachable by the user agent, with the processing model that, when directed to navigate via the hyperlink, the UA will try fetching each location in sequence until one succeeds. (This process may or may not be transparent to the user.)

This specifically targets the situation where the HTML author doesn't have control over the server hosting (the primary location of) the resource, so mirrors for the purposes of, e.g., load balancing or providing the physically closest server to the client computer are out of scope (both of these can be implemented today with a single URL that redirects).

Use case 1: an HTML author wants to provide users with a third-party snapshot (a la Wayback Machine or archive.today) of a web resource the author suspects may disappear.

  • Requirements:
    • Must be able to direct the UA to try the primary source first.
    • Must be able to provide one or more fallback URLs for the UA to use if the primary source is unavailable.
    • If a fallback URL is used, the UA must not obfuscate the fact—an address bar should display the URL used, for example.
    • If a fallback URL is used, the UA's session history should not include the URLs that were tried and failed—for example, clicking a back button should return to the page containing the original hyperlink-with-multiple-locations, not a 404 response page retrieved from the primary source.

(Note that a provide-two-a-elements implementation of this pattern is used extensively on Wikipedia, as documented here. The verbosity of this pattern could be avoided if the UA was able to navigate to the best available location transparently. However, I don't speak for anyone involved with Wikipedia standards and they would not necessarily want to use this feature for this application, if made available.)

Use case 2: an author wants to provide a proxied URL in case network censorship blocks the unproxied URL.

  • Requirements: as above

Use case 3: an author wants to provide a local snapshot of a web resource for either of the above reasons.

  • Requirements: as above

Use case 4: an author wants to link to a resource using an exotic URL protocol that UAs may not support, and provide an HTTP(S) fallback for other UAs.

  • Requirements:
    • UAs may use a fallback URL if the protocol for the primary URL or an earlier fallback URL is not recognized.
  • Possibly related: #4584

rhendric avatar Mar 07 '23 00:03 rhendric

I would like this for href and src attributes.

One suggestion is to allow multiple URLS inside the href and src tags as fallbacks and these URLs can be separated with a space. The integrity and crossorigin attribute can also be separated with a space for each URL and for any URLS that do not have a integrity hash, a dash - can be used to indicate the URL does not need to be checked.

Here is a simple example...

<link rel="stylesheet" href="https://alpha.com/style.css https://bravo.com/style.css https://charlie.com/style.css" integrity="sha512-ykZ1QQr0Jy/4ZkvKuqWn4iF3lqPZyij9iRv6sGqLRdTPkY69YX6+7wvVGmsdBbiIfN/8OdsI7HABjvEok6ZopQ== - sha512-V7mESobi1wvYdh9ghD/BDbehOyEDUwB4c4IVp97uL0QSka0OXjBrFrQVAHii6PNt/Zc1LwX6ISWhgw1jbxQqGg==" crossorigin="anonymous - anonymous">

<script href="https://alpha.com/script.js https://bravo.com/script.js https://charlie.com/script.js" integrity="sha512-ykZ1QQr0Jy/4ZkvKuqWn4iF3lqPZyij9iRv6sGqLRdTPkY69YX6+7wvVGmsdBbiIfN/8OdsI7HABjvEok6ZopQ== - sha512-V7mESobi1wvYdh9ghD/BDbehOyEDUwB4c4IVp97uL0QSka0OXjBrFrQVAHii6PNt/Zc1LwX6ISWhgw1jbxQqGg==" crossorigin="anonymous - anonymous"></script>

trymeouteh avatar Jul 09 '24 22:07 trymeouteh

urls with spaces are legal so that's a non-starter. what about sibling <link>s with differing values for href but the same integrity ?

eg:

<link rel="stylesheet" href="https://necolas.github.io/normalize.css/8.0.1/normalize.css" integrity="sha384-M86HUGbBFILBBZ9ykMAbT3nVb0+2C7yZlF8X2CiKNpDOQjKroMJqIeGZ/Le8N2Qp" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css" integrity="sha384-M86HUGbBFILBBZ9ykMAbT3nVb0+2C7yZlF8X2CiKNpDOQjKroMJqIeGZ/Le8N2Qp" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/normalize.css" integrity="sha384-M86HUGbBFILBBZ9ykMAbT3nVb0+2C7yZlF8X2CiKNpDOQjKroMJqIeGZ/Le8N2Qp" crossorigin="anonymous">

nektro avatar Jun 17 '25 22:06 nektro

the creation of https://github.com/whatwg/html/issues/11376 got me thinking about this again because i think another solution could look something like this:

<link rel="stylesheet" href="http://npm.localhost/[email protected]/normalize.css" integrity="sha384-M86HUGbBFILBBZ9ykMAbT3nVb0+2C7yZlF8X2CiKNpDOQjKroMJqIeGZ/Le8N2Qp" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css" integrity="sha384-M86HUGbBFILBBZ9ykMAbT3nVb0+2C7yZlF8X2CiKNpDOQjKroMJqIeGZ/Le8N2Qp" crossorigin="anonymous">

with http://npm.localhost being an app running on the user's machine to serve locally cached libraries without any commitment from the browser

nektro avatar Jun 17 '25 22:06 nektro