tc39 / proposal-built-in-modules

BSD 2-Clause "Simplified" License
892 stars 25 forks source link

Import semantics #46

Open jikkujose opened 5 years ago

jikkujose commented 5 years ago

Was looking at the proposals for adding protected name spaces & using stuff like: std: to prefix the standard libraries. Can it be done like so:

Why not consider this as a simple cache rather than something special:

With async modules, the preprocessors will start splitting bundles for this.

Advantages:

  1. There is nothing special in importing it, if it isn't available in the cache it gets downloaded. Just ordinary memoization.
  2. It will work in browsers that doesn't support it without any changes
  3. Maintaining whitelist is much simpler, and browsers can differ in opinion what to contain in their list. This will reduce a lot of decision time.
  4. Users can also have control over the whitelist, they can add or delete stuff from it
  5. Browser can offer to add packages based on browsing patterns
  6. This would be a simple "make available offline" if website bundles are added to the whitelist

Disadvantages

  1. Dependency on npm/cdns in a standard solution
glen-84 commented 5 years ago

This seems related to #18.

I had a similar idea back in 2009.

I think there are concerns about hash collisions and other related security issues. See #18 for more information.