Skip to content
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

std:x|y is not a valid URL #15

Open
hiroshige-g opened this issue May 4, 2018 · 17 comments
Open

std:x|y is not a valid URL #15

hiroshige-g opened this issue May 4, 2018 · 17 comments
Labels
fallback syntax An issue with the syntax for falling back from a LAPI to a polyfill

Comments

@hiroshige-g
Copy link

"|" is not a valid URL code point.
https://url.spec.whatwg.org/#url-code-points

Also related to #14 that proposes adding " " which is also not a valid URL code point.

@domenic domenic added the fallback syntax An issue with the syntax for falling back from a LAPI to a polyfill label May 7, 2018
@domenic
Copy link
Collaborator

domenic commented May 7, 2018

@annevk do you have thoughts on this issue? Any reasons why | is not a valid URL code point?

We may not need to worry about this if we end up switching approaches for LAPI fallbacks entirely. But if we do stick with std:x|y in the long term, we should resolve this; it's not good to encourage web developers to use "invalid" URLs, even if browsers handle them fine.

Some quick fix ideas:

  • Make | valid
  • Use a different choice of punctuation. None of them communicate "alternate" the same way IMO, but something like + or @ or ! or ~ is not the worst plan.

@ojanvafai
Copy link
Collaborator

There's also: std:x?fallback=y. It's less pretty, but it's clear, it's a valid URL, and would allow us to add extra parameters in the future if needed (not sure if that's a good thing though!).

@annevk
Copy link

annevk commented May 8, 2018

For validity the URL Standard follows https://tools.ietf.org/html/rfc3987 to encourage producers to make URLs that work in most places. I don't really know the rationale behind |.

@watilde
Copy link

watilde commented Jun 14, 2018

Rather than implementation as a string, could not we allow import from to use ||?

@domenic
Copy link
Collaborator

domenic commented Jun 14, 2018

How would that work with script src?

@watilde
Copy link

watilde commented Jun 14, 2018

As the original proposal said, using attribute stdsrc works fine imo. Having both looks like bringing high affinity with current behavior. It still has a concern of standardizing attribute pairs for every place a layered API URL, but might be better for backward-compatibility.

@domenic
Copy link
Collaborator

domenic commented Jun 14, 2018

Hmm, having to use a different syntax depending on the call site seems like a big disadvantage to me.

@annevk
Copy link

annevk commented Jun 14, 2018

Any reason / is not acceptable here?

@devsnek
Copy link

devsnek commented Jun 14, 2018

even if | was valid in urls (or any other separator) it feels like a hack to get around making syntax, which i think would be more explicit with the intention and be easier to parse.

is amending the html parsing spec acceptable?

crazy: <script type=module src=[want, fallback1, fallback2]>

browsers supporting this feature could allow duplicate attributes which i think would also be backward compatable: <script type=module src=want src=fallback1 src=fallback2>

as for js syntax i like import x from want || fallback1 || fallback2

@domenic
Copy link
Collaborator

domenic commented Jun 14, 2018

The intention is specifically to use the existing string and URL infrastructure, and not to invent some new thing besides URLs (such as bracketed collections of strings, or logical-ORed-together strings) for loading modules.

@watilde
Copy link

watilde commented Jun 15, 2018

Is that something like an indispensable condition to use the existing string at the two different places(import/script module <= URL), or it's fine to use the two different ways(the above suggestions) if both of them solve the same problem and if it's even better at fewer dependencies?

@domenic
Copy link
Collaborator

domenic commented Jun 15, 2018

I think any solution which introduces two separate ways of creating fallbacks, and requires developers to have to memorize which apply in which contexts, is significantly worse than any solution which only has one such way.

I don't think it's a requirement that you only use one, but the benefits of using two (or more) would have to be extremely compelling, and so far nobody has really presented any reasons why two is good that I was able to understand.

@matthewp
Copy link

If | becomes valid, would this be something that developers could leverage some how? Meaning would the URL constructor be updated to include a fallback property? And if so, I'm assuming this would only be possible on std: type of URLs...

@domenic
Copy link
Collaborator

domenic commented Jun 15, 2018

We had a productive discussion in IRC that people might find illuminating.

I think right now, for a fallback syntax in the URL, I'm tending toward std:x?fallback=y as @ojanvafai suggested upthread. It seems like std:x|y causes a lot of confusion because people don't have the same intuition about | as they do about query params. But the semantic intent was the same. This wasn't meant to be a new feature of URLs in general, just a particular way of encoding how to locate the contents of a resource. I think the use of | just got too "cute".

But that said, I'm also continuing to think we should remove the fallback syntax for now, in favor of a package name map based solution. I'll post a pull request about that soon.

@wanderview
Copy link

Wouldn't ?fallback= require URL encoding the fallback URL in the search param? I thought one advantage of special syntax like "|" would be that it could avoid the URL encoding requirement and be more ergonomic.

@matthewp
Copy link

One advantage of add syntax like | is that it becomes a generic solution for fallbacks. The ?fallback query param will work for std: URLs if you define it that way, but won't work as a fallback for multiple http(s) URLs. This is something people have wanted for a very long time in order to prefer loading a script from a CDN but then falling back to a local resource.

If we had | we could do:

<script src="https://cdn.com/jquery.js | ./assets/jquery.js"></script>

Currently people use document.write() (yuck) to do the above.

@matthewp
Copy link

Ok, I see now that package name maps could possibly be a generic solution for fallbacks. If so that works for my use case.

domenic added a commit that referenced this issue Aug 3, 2018
This incorporates some of the ideas touched on in the issue tracker, mostly around using package name maps to provide a better fallback story and web developer control. It touches on the following issues:

* Fixes #10, fixes #14, fixes #15, and fixes #24 by moving away from std:x|y and its attendant problems.
* Opens the door to solutions for #5 based on the speculative package name map fallback ideas.

It also adds a bit more motivation to the intro, and rearranges to emphasize the standards process, before diving into many details on the importing infrastructure.

For now we delete the "Trying these ideas out" section, and spec.md, as they are all about the old infrastructure.
domenic added a commit that referenced this issue Aug 3, 2018
This incorporates some of the ideas touched on in the issue tracker, mostly around using package name maps to provide a better fallback story and web developer control. It touches on the following issues:

* Fixes #10, fixes #14, fixes #15, and fixes #24 by moving away from std:x|y and its attendant problems.
* Opens the door to solutions for #5 based on the speculative package name map fallback ideas.

It also adds a bit more motivation to the intro, and rearranges to emphasize the standards process, before diving into many details on the importing infrastructure.

For now we delete the "Trying these ideas out" section, and spec.md, as they are all about the old infrastructure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fallback syntax An issue with the syntax for falling back from a LAPI to a polyfill
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants