Skip to content

Allow exporting without a script #9

Closed

Description

@phistuck

Define a new HTML content attribute, export or exportname or namedexport (and defaultexport?) or something similar that allows elements to be exported without any inline scripts.

<!-- module.html -->
<div namedexport="content">
Warning - this might hurt.
</div>
// main.js
import {content} from "module.html";
document.body.appendChild(content);

I imagine some HTML modules might have no scripting logic, they would only exist to share content and inline scripts are too wordy for those cases.

That could maybe make them available from HTML directly as well...

<!-- Bonus -->
<!-- page.html -->
<content import="module.html" namedimport="content"></content>

A little bit like server-side includes. But this is crazy talk.

Activity

  1. travisleithead commented on Jan 17, 2019

    @travisleithead
    Contributor

    We've definitely had discussions about this possibility, since it seems very natural to enable import/export declaratively. One thing we are losing with HTML Modules, which was available via HTML Imports is the declarative import via link[rel=import]. It's not a huge loss, since static module imports can be readily identified in top-level script texts almost as easily. Our approach was "wait and see", as declarative support can be added later with no backward compatibility issues.

    Do you have thoughts on how import/export might work with template? If you think about template as able to import an external html module, I think things start to get interesting...

  2. kenchris commented on Jan 22, 2019

    @kenchris
    Contributor

    Instead of using

    <content import="module.html" namedimport="content"></content>

    we probably want something similar to named slots

    <p><slot importname="my-text">My default text</slot></p>
  3. kenchris commented on Jan 22, 2019

    @kenchris
    Contributor

    Travis Leithead (@travisleithead) maybe something like:

    <template import="summary-data.html">
      <details>
        <summary>
          <code class="name">&lt;<slot name="element-name">NEED NAME</slot>&gt;</code>
          <i class="desc"><slot name="description">NEED DESCRIPTION</slot></i>
        </summary>
        <div class="attributes">
          <h4>Attributes</h4>
          <slot name="attributes"><p>None</p></slot>
        </div>
      </details>
      <hr>
    </template>
  4. Jamesernator commented on Jan 25, 2019

    @Jamesernator

    This would be nice if it works without scripting enabled too as we could have a nice fallback that is downloaded only if scripting isn't enabled rather than shipping it to everyone:

    <noscript>
      <content import="no-script-fallback.html"></content>
    </noscript>
  5. matthewp commented on Mar 6, 2019

    @matthewp

    This is definitely an interesting issue. However there's also some overlap I feel with the declarative custom elements strawman. Given that, it might be advantageous to defer this until after HTML modules have landed. Otherwise I feel there is risk that the whole thing becomes blocked. From what I can tell I don't feel this proposal would be affected by any of the choices already made in HTML modules (meaning it could be added later).

  6. domenic commented on Mar 6, 2019

    @domenic

    I tend to agree this seems additive, and it's worth getting the foundations down first.

  7. travisleithead commented on Jan 8, 2020

    @travisleithead
    Contributor

    Closing this issue and opening a linking issue in the webcomponents repo. (WICG/webcomponents#863)

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions