How to get the module URL for custom-element?

Answer: by defining following attributes in module-url:
  1. src with path to module resource, If omitted, it would match the window.location.href
  2. slice to read the URL
URL properties would be a part of slice data, the value would be a full URL.

Where to use module-url?

Answer: to inject the library resources URL into generated HTML.

Import maps are used for defining the dependencies location on the web page level. This way dependencies could reside on different CDN path or even domains while in the code would be referenced by symbolic package name. See the CDN example bellow.


The resolving of import maps is done by import.meta.resolve(path)

Where NOT to use module-url?

Answer:
  1. in scr attribute of <custom-element >
    - It uses the same module resolving mechanism
  2. for getting/setting the page URL,
    - see How to set page URL in custom-element?

See also

How to use external templates?

embed-lib resolved to ./lib-dir/embed-lib.html by page importmap

As fakedemo-lib is not in importmaps, the symbolic name is not resolved and renders the error

lib-root resolved to lib-dir by page importmap