GithubHelp home page GithubHelp logo

link instead of script? about import-maps HOT 11 CLOSED

wicg avatar wicg commented on August 18, 2024
link instead of script?

from import-maps.

Comments (11)

matthewp avatar matthewp commented on August 18, 2024

With <link> you couldn't inline the map in the HTML. You could put it in a header but many servers have size limits on headers that the package map might exceed.

from import-maps.

matthewp avatar matthewp commented on August 18, 2024

I take that back, looks like the typical size limit is 8k, I doubt a packagemap would exceed that. I had thought the limit was smaller.

from import-maps.

bmeck avatar bmeck commented on August 18, 2024

@matthewp if the link header is mostly a href I don't think it likely to exceed the size limits. Per inlining into the document, I'm not sure if a precomputed workflow like this is as desirable to output back into inline HTML for most situations. If desirable to inline we could certainly support both ways to load things, similar to CSS.

I somewhat still question if inlining is going to be more desirable than linking since you will be doing many resource requests most likely as the README states. Inlining can help with initial load, but could cause fewer cache hits on the initial document load if the package name map changes over time. In particular, being unable to load updated package name maps after initial load means that any changes would require a refresh in order to be synced up. Hopefully, we can find a workflow where package name maps change rarely; I am unsure of that being realistic.

from import-maps.

matthewp avatar matthewp commented on August 18, 2024

Good point about cache hits. For a lot (but not all) sites, caching isn't used on documents as they tend to be dynamic. I'm concerned about using hrefs with http/1.1 servers though. The packagemap is a super-dependency of all modules, so it will block the preload scanner from doing its job.

from import-maps.

justinfagnani avatar justinfagnani commented on August 18, 2024

We considered both, but started with <script> because of inlining, and not wanting to have two ways to do the same thing.

from import-maps.

matthewp avatar matthewp commented on August 18, 2024

@justinfagnani I'm curious about this:

Adding a second <script type="packagemap"> has no effect.

Should we be concerned that a large packagemap will block scripts from loading? One case where you might want multiple packagemaps would be if you wanted to put essential, above-the-fold scripts into its own tree and then defer the rest for later. For example:

<script type="packagemap">
  [ESSENTIAL MAPPING HERE]
</script>
<script type="module" src="./main.js"></script>

<main> ... </main>

<script type="packagemap">
  [NON-ESSENTIAL MAPPING HERE]
</script>
<script type="module" src="./less-important.js"></script>

The question being whether a packagemap is ever big enough where splitting would be desired. I understand that allowing multiple maps starts to raise conflict resolution problems...

from import-maps.

justinfagnani avatar justinfagnani commented on August 18, 2024

I hope that can be explored more, and my team has asked for it. I understand that there might be blockers, but maybe there's some way to figure it out.

from import-maps.

justinfagnani avatar justinfagnani commented on August 18, 2024

btw, this is a dupe of #1

from import-maps.

domenic avatar domenic commented on August 18, 2024

Hmm, I really tried to pre-empt this by pre-filing #1. Let's please continue discussion there? Some good points have been raised so far though!

from import-maps.

bmeck avatar bmeck commented on August 18, 2024

@domenic I'm not sure this fits in either #1 or #2 since the link: header could apply to both.

from import-maps.

domenic avatar domenic commented on August 18, 2024

Well, I agree the issues slightly bleed over, but since #1 is where <script> is the existing proposal, we'd need to establish that link is good enough or better for the window context before considering it for the worker context.

from import-maps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.