Repository navigation
Description
We keep seeing efforts to extend specifiers to additional types of resources, for example Declarative adoptedStyleSheets for Sharing Styles In Declarative Shadow DOM which extends the concept of specifiers to refer to CSS stylesheets:
<style type="module" specifier="my-component-styles">...</style>
<my-element>
<template shadowrootmode="open" shadowrootadoptedstylesheets="my-component-styles">
<div>...component content...</div>
</template>
<my-element>Essentially, specifiers are an abstraction over URLs, and a quite useful one at that when multiple packages from different sources are coordinating. In some ways, they provide the benefits of a relative path, without having to figure out the right relative path.
Additionally, the motivation behind many of these efforts is the way the JS module graph circumvents excessive HTTP roundtripping.
Neither of these benefits are fundamentally tried to JS, and I suspect we will see more of these efforts over time.
However, while ESM import syntax was designed with specifiers in mind and syntactically disambiguates between the two, the vast majority of the platform was designed to be URL-first and cannot be retrofitted to accept specifiers. For example, this means that <link rel=stylesheet> or the CSS @import syntax would not be able to read these CSS specifiers, making something like CSS modules an ad hoc feature specifically for the benefit of web components. Even for JS, <script type="module" src> cannot accept specifiers. Yes, we can invent ad hoc syntax to enable specifiers to be used in every one of these cases (e.g. @import specifier(foo)), but given the places resources can be imported, that seems like a lot of (likely inconsistent) API surface.
A potential solution could be to fully embrace specifiers as a high-level abstraction over URLs and do something along the lines of:
- A new
specifier:URL protocol. Specifier URLs resolve to an actual URL before being fetched, but which URL they resolve to also depends on the request'sOriginheader (so that import map scopes function properly) - In certain contexts (such as ESM imports or this new
shadowrootadoptedstylesheetsattribute) thespecifier:protocol is implied - HTTP caching would work differently; basically in a way that emulates the current behavior of the JS module cache.
- This proposal is not concerned about how specifiers resolve at all, this is the subject of other technologies/proposals. This is about hooking in to the existing resolution mechanisms, whatever those are (import maps, HTTP headers, etc).
Obviously this is an early sketch/strawman and very handwavy, not a detailed, fleshed out proposal.
Architecturally, this has the advantage that it bridges the gap between specifiers and URLs. Rather than having two entirely separate primitives for linking to a resource, it makes specifiers the high-level primitive and URLs the low-level primitive that explains it, making the mental model around resource fetching more coherent and easier to explain.
In terms of use cases, it can be incredibly powerful: ultimately specifiers could be used anywhere a URL can, including images, videos, import map URLs (alias specifiers to other specifiers!), <iframe src>, SVG <use>, CSS url() etc. Though it doesn't have to ship to all of these at once (see below).
Implementation-wise, implementing this properly would be a big task. URLs are handled all over the place and it would likely break assumptions all over the codebase. However! What could work is prototyping it with ad hoc handling, but in a way that creates the illusion of general URL handling. E.g. instead of having an ad hoc CSS syntax like @import specifier(blah) which will be ad hoc forever, implement @import url("specifier:blah") but resolve to a URL as part of @import handling (based on the existing mechanisms to do so, e.g. import maps), then propagate a URL for any further handling. Then later down the line once more parts of the codebase have been handling specifier: URLs, explore refactoring to move it under general URL handling. That way, implementation effort would be the same as ad hoc syntax, but the author-facing API surface is the same everywhere. The downside is that for a while we'd be in the awkward middle ground where specifier: URLs work in some places but not others, but IMO swapping a permanent problem for a temporary one is a win.
I’ve run the above by @yoavweiss who agreed (Yoav please correct me I misrepresented anything!) and added:
OK, implementation-wise I think it can work if you define some
SpecifierOrURLhandling class and use it in a small number of places, expanding over time
Activity
[-]`specifier:` URL protocol for using specifiers in web platform places that were not designed for them[/-][+]`specifier:` URL protocol for retrofitting specifiers in places designed for URLs[/+]sorvell commentedon Feb 21, 2026
I fully support this concept. The ability to map specifiers to URLs is incredibly useful, and it's a major platform flaw that this feature is currently restricted to module scripts.
One concern I have here is that, as I understand it, the module system doesn't cache the fetched resource, it caches the result of processing the fetched resource. This might be a mismatch here and/or require additional syntax to clarify the intent, at least in some cases. For example, assume here that an
importmapexists for"foo": "./foo.css":In that sheet
rule[0].styleSheet !== rule[1].styleSheet, and I believe that's not up for debate.But does
rule[2].styleSheet === rule[3].styleSheet? If they act like JS modules, then the answer is yes. I very much want this to be the case. Is that the intention here?LeaVerou commentedon Feb 21, 2026
Yes, that is the intention here. The fact that it's not the case for URLs is unfortunate. Ideally, we'd want to solve this for URLs too, in a backwards compatible way. Basically, a behavior that URLs can opt-in to that does this, but specifier URLs have it by default. What would that look like? An HTTP header?
sorvell commentedon Feb 22, 2026
Related specifically to @import: w3c/csswg-drafts#8297. Also mentioned in that issue is @jakearchibald's proposal for fetch-maps, which has at least some of the caching but via a separate namespace I think.
KurtCattiSchmidt commentedon Feb 25, 2026
This is super interesting. A few questions/potential gotchas:
import foo;andimport specifier:foo;are equivalent for script-based specifier imports, or is this proposal only targeted to HTML + CSS?<base>, and it might be helpful to list out differences or pro's/cons so it doesn't get confused or sidetracked. It also might help to describe how this is expected to work with<base>(I assume specifiers ignore<base>, but I'm not positive, it might still apply after import map resolution).asyncanddefer, so it can wait until all content (including import maps) have been parsed before executing (if desired). HTML has no such constructs, so you could have:...and only the second
<link>would have its bare specifier mapped via the import map. This is different than how resource fetching works in HTML, where the order of parsing the DOM doesn't impact URL resolution.One possible solution to this kind of thing would be to introduce
asyncordefer-like attributes for each of these, which won't scale everywhere (e.g. CSS@importdoesn't take an attribute, so it would require updates to its grammar, and I would imagine there are other strange cases). Deferring the fetch could postpone the overall load time pretty significantly though, so maybe the ordering dependency is less bad?<link rel="styleshet">or@import, you could get race conditions like this:(where
a.csshas@import(specifier:foo))Then you have:
a.cssgets fetched asynchronously, and parsing continues. The CSS@importfetching behavior is somewhat vaguely spec'd, but the actual behavior in browser engines seems to be async fetches with a synchronous ordered insertion of imported rules once each fetch completes. The async fetch ofa.cssmeans that fetchingspecifier:foocould fail, as it would be racing with the import map parsing.One option is to defer these types of fetches until parsing is complete as suggested in 3). Waiting to fetch resources until parsing completes is bad, and this would also break optimizations like the speculative parser. This case seems worse than the ordering dependency in 3), as it's non-deterministic.
sorvell commentedon Feb 26, 2026
That seems fine to me and is, I think, de facto what happens with importmaps and module scripts. For example,
If there's ordering, then it seems like the fetching resource (e.g. owning link or style) needs to bake a copy of the importmap to use for any fetches it spawns. Seems like that would avoid a race and be straightfoward to reason about. I hope that's practical.
KurtCattiSchmidt commentedon Feb 26, 2026
@sorvell - this wouldn't cover if the document's import maps change during the fetch though. It would have the stale copied version, so the race still exists.
LeaVerou commentedon Feb 26, 2026
@KurtCattiSchmidt Great questions!
Yes, that’s the idea.
That's an interesting connection. They are quite different:
<base>specifies the base URL to use for all relative URLs. It does not affect specifiers, since they are not relative URLs, and it should not affectspecifier:URLs since they would be absolute, so that is internally consistent.It does apply after import map resolution (see testcase) but that doesn't change with
specifier:URLs.It's not about resource fetching in HTML vs JS, it's about when the UA discovers the specifier.
Note that this does not work today (testcase):
Neither URLs nor specifiers are revisited multiple times. If the resource being fetched is using specifiers however, these attributes may defer its loading until after the import map has been processed. None of this changes. Yes, it does mean that any resources using specifiers would need to generally come after import maps, but that's not new.
WRT async/defer for
<link>,@importetc, these are orthogonal primitives, and need to be discussed in their own proposals, some of which are:specifier:URLs may add to the motivation around them, but neither is blocking the other.Btw CSS
@importcan take additional annotations (media queries,supports(),layer()), so it wouldn't be a huge lift in terms of grammar.Note that
specifier:URLs don't need to be restricted to CSS and JS. With this, ultimately specifiers could be used anywhere a URL can, including images, videos, import map URLs (alias specifiers to other specifiers!),<iframe src>, SVG<use>, CSSurl()etc. I added a note to the OP in case it wasn't clear.I don't think it breaks the speculative parser, it just means these particular speculative fetches cannot happen until any import maps have been parsed, which seems fine to me?
In general, this is assuming the JS behavior where undefined specifiers fail early. JS has very good reasons to handle them that way, but we are not bound by the same constraints everywhere in the platform. For independent fetches that don't affect anything else, such as CSS
@import, there is no reason to fail eagerly if you encounter aspecifier:URL you can't resolve, you could just wait longer.Also, we should define
@importfetching less vaguely! Would you mind opening an issue?sorvell commentedon Feb 27, 2026
This makes sense to me. The race condition @KurtCattiSchmidt points out exists today with importmaps and js modules. Here's a test case (try setting the timeout in barMapDelay to be > barImportDelay).
In general, I think the best practice with importmaps is to define them early and as long as you do that, it shouldn't be an issue?
noamr commentedon Aug 6, 2026
The main issue with this is that it doesn't answer the question of how you use modules from the map in those places, regardless of the import map.
e.g. let's say you don't have an import map at all, but you are using a module in
/style/theme.css.Right now calling
@import "/style/theme.css"would re-fetch that URL, ignoring the module map. Aspecifier:scheme is not the right primitive for this.I think what's needed is a map of places where modules can be reused alongside non-modules, and see what is the right way to specify that the importing happens from the module map (and referring to the import map as part of that) rather than as a regular fetch.
It could be
@import module "/style/theme.css".We can go with
@import "module:/style/theme.css"which might mean also@import module:https://cdn.example.com/style.css".When looking at the use cases - I wouldn't jump to a generic solution though it might be tempting. Including HTML modules in
<iframe src>or SVG modules in<use>, or image modules in CSSurl()sound like possible future use case but in fact bring a lot of questions and complications about mutability, that might lead us to a completely different syntax.robglidden commentedon Aug 14, 2026
In light of the new "Style Module Imports via
<link>Elements" explainer ...I think only a small set of HTML attributes would actually benefit from SpecifierOrURL handling, and for those I think a new attribute, say
importfrom, is worth considering over a protocol.Of the 14 URL-bearing attributes in 27 HTML elements (please expand and check my list and reasoning below), and excluding ~13 additional obsolete attributes, really only
<link href>and plausibly ~2-3 others are good candidates. This comment doesn't address CSS or SVG.I note that during the original design of import map, an
import:scheme was proposed in 2018, scaled back to only CSS and HTML, and ultimately dropped in 2021.What was not considered then, and I think should be now, is a new attribute like
importfrom.An
importfromattribute offers distinct advantages over a protocol:href="specifier:foo"results in a network error, see scheme fetch)In the specific case of "Style Module Imports via
<link>Elements":typetotype="module"hrefa dual-purpose attribute which triggers different behaviors of the link element itself, which is confusing and error-proneI note the design principle above already names overloading
hrefas a mistake not to repeat:SpecifierOrURL processing rule:
If
importfromis present and supported, it wins andhrefis ignored.href, loads a working stylesheet. No error, no console noiseimportfromthrough the import map, ignoreshrefElements with URL attributes and reasoning
I examined the WHATWG HTML attributes index and cross-checked for example against the spec's own parse a URL call sites, and against Gecko's URL-attribute table, a literal array,
kURLAttributesHTML.Filtering the attributes index on the string "URL" alone is not enough.
srcsetand<meta http-equiv=refresh content>have URLs in a larger syntax and don't declare "URL" as their value type.I found 14 URL-bearing attributes, across 27 elements:
href:<a>,<area>(navigate on activation),<link>(behaviour depends onrel),<base>(sets the document base URL)src:<img>,<script>,<iframe>,<embed>,<source>,<video>,<audio>,<track>,<input>srcset:<img>,<source>— URLs inside image candidate stringsimagesrcset:<link>— URLs inside image candidate stringsposter:<video>data:<object>action:<form>— submission targetformaction:<button>,<input>— submission target overrideping:<a>,<area>— space-separated URL list, POSTed out-of-bandcite:<blockquote>,<q>,<ins>,<del>itemid,itemtype,itemprop: global microdata attributescontent:<meta http-equiv=refresh>— URL inside a text value; declared value type is "Text"~13 obsolete attributes:
longdesc,archive,codebase,classid,profile,manifest,background,lowsrc, and so on. I don't see value in retrofitting these for SpecifierOrURL handling.Of the 14, 2 are clear candidates for SpecifierOrURL today:
<script src>: already module-aware<link href>: the exact situation of LinkTagModuleImport explainer<img src>/<img srcset>are plausible, giving at most 4.I excluded the rest for 3 reasons:
Never dereferenced (5).
cite,itemid,itemtype,itemprop, and<base href>. Nothing fetches these, so there is nothing for import-map resolution to do. All three browser engines omititemid/itemtype/itempropfrom their URL-attribute tables (e.g. Gecko'skURLAttributesHTML).itemtypevalues likehttps://schema.org/Personare deliberately stable global identifiers, and remapping would defeat their purpose.base hrefis itself a resolution mechanism.Fetch, but no module-graph use case (5).
action,formaction,ping,poster, and<track src>. These fetch or navigate, but nobody has asked for import-map-resolved form endpoints or ping URLs.Navigation or document/plugin loading, not module loading (4).
<a href>,<area href>,<meta refresh content>, anddataon<object>(along with<iframe src>and<embed src>). These name documents to navigate to or embed, not resources to load into a module graph.That leaves
srcsetandimagesrcset. These would need something other than a parallelimportfrom, because the URL is not the whole attribute value, it is in a comma-separated microsyntax withw/xdescriptors.noamr commentedon Aug 14, 2026
@robglidden if we have
<link rel=stylesheet type=module>, what is the advantage of having eitherspecifier:orimportfrom? Where would you use this outside of importing stylesheets?robglidden commentedon Aug 17, 2026
@noamr:
To me,
<link rel=stylesheet type=module>is better thanspecifier:butimportfromis better than both, because it offers a progressive enhancement strategy, avoids a hard fail on non-supporting browsers, and avoids repurposing existing attributes to subtly-new semantics.Summarizing:
<link rel=stylesheet type=module>no onerror()
does onerror()
This may help address 2 open issues in the "Style Module Imports via Elements" explainer:
Should we attempt to make this feature backward-compatible with classic elements, or are there too many differences?
Is href the right way to go, even though it goes through import map processing? Should we use a new attribute such as moduleimport?
The list of candidate url-loading existing elements is small, this comment (please recheck!) identifies only
<link href>,<script src>,<img src>,<img srcset>of existing HTML elements. I think one could also add the SVG element<use href>.But the idea of different situation-specific URL attributes depending on context is well established: 14 URL-bearing attributes, across 27 elements.
From all this it seems to me:
importfromis likely a better and more precedent-based and platform-design-principles-based solution than a new protocol likespecifier:.Also, I think the full set of import parameters should be considered, and not just munge "specifier" with "import map key":
There are several potential overlapping and conflation issues there ("type", "as", "with", default, etc) when remapped to a smaller set of declarative attributes and import map processing.
noamr commentedon Aug 18, 2026
Ah ok for progressive enhancement we could do that or:
link rel="stylesheet module"
Which would ignore "module" on unsupported browsers without introducing a new attribute.
The thing is that it will still fail on unsupported browsers if using module specifiers from the importmap, which makes me think that it's perhaps better for it to fail rather than sometimes succeed and sometimes fail... But I am not sure.
LeaVerou commentedon Sep 15, 2026
I think we need to distinguish import-as-module (make a resource part of the module graph) vs specifier import.
Importing a URL as a module does not automatically allow us to use specifiers, and last I checked Style Module Imports did not account for specifiers at all.
Specifiers are essential for proper dependency management on the web platform. They decouple a dependency from…
Even a
<script>element, which already supportstype=module, does not actually support specifiers.And there are many use cases for importing non-JS assets, from CSS libraries to icons, graphics, media files, etc. for which the web platform currently has no good story.
Sure, we could introduce ad hoc syntax for every single case. And then more ad hoc syntax in CSS, and more ad hoc syntax in SVG, and so on. This is exactly what this proposal aims to avoid. The more special syntax we add, the more the API surface authors have to learn, and the slower the rate of progress because everything now requires a bikeshedding session .
Or we can target the one syntax all of these understand: URLs.
This does not negate the value of supporting
type=moduleon certain resources to add a (regular) URL to the module graph. These are separate things.noamr commentedon Sep 27, 2026
The main point is that importing from the specifier map means that the resource is imported from the module graph.
In what cases does importing from the module graph doesn't go through the
importmap?I think it does?
import sheet from "theme-styles" with { type: "css" }should check the import map for atheme-stylesspecifier.Can you expand on that? specifiers are part of an importmap and are supported whenever a module import is supported (not to be confused with CSS
@importunfortunately).We would need ad-hoc understanding of what importing from the module graph means in all these cases... what does it mean for SVG to import from the module graph?
A
specifierURL doesn't solve anything in that regard... if at some points certain parts of SVG fetch via the module graph, they should also resolve URLs using the importmap.The importmap is nothing but a glorified URL alias system for the module graph... A custom scheme is the wrong abstraction for that IMO as it's not valid anywhere outside the module graph and it always needs to be consulted with when importing from the module graph anyway.
LeaVerou commentedon Sep 27, 2026
@noamr
<script src="foo" type="module"></script>will not use afoospecifier:fooin that context already has a defined meaning, it's a relative URL to the file calledfoo. Try it. 🙂That is literally the whole point of this proposal. You cannot retrofit specifiers in places designed for URLs, because they are already interpreted as relative URLs and we cannot change that. No wonder you reached the conclusion that there is no point if there's such a fundamental misunderstanding.
Last I checked style module imports were also framed around URLs, including plain relative URLs, which preclude specifiers from ever being supported in these places.
By style module imports I'm not referring to CSS modules, I'm referring to the new
<link rel=stylesheet import="foo.css">proposal.ESM imports avoided this entire problem by not allowing these: a relative URL has to start with
./or../.Specifiers are indeed an abstraction over URLs — an essential one for dependency management. The reason people use specifiers is not because they look a little prettier. It's because they decouple a dependency from:
Worse, lack of specifiers rules out transitive dependencies because there's nothing reasonable to reference.
Specifiers are not a nice-to-have.
Until we can use specifiers everywhere a dependency may be useful, the web platform is bound to depend on bundlers forever for dependencies (and still have "dependency management" come 3rd as a pain point). You may think this is fine, but we should all be aware of what future we are designing for the web platform.
Perhaps the mistake of this proposal was coupling
specifier:with the module graph. They can be entirely separate. It's a bit of a missed opportunity, but it does alleviate the core pain points this proposal was designed to address.noamr commentedon Sep 28, 2026
I think we can make this work directly from the import map without changing the URL?
In any case, this does not seem particularly useful.
It would only do something special if it's a module that's not anyway imported from somewhere else, and it's just 2-3 characters more than
<script type="module">import "foo"</script>It's a side note in the OP. The OP is mostly about styles etc.
When importing styles, we would need access to the module graph regardless of specifiers.
The
@import(e.g.@import "https://example.com/style.css")needs to know if it gets the style from the module graph or by fetching.Style module imports go to the importmap first as currently specified.
I love the importmap, there is no argument about that.
Yea if this proposal expands to make the
importmapor an equivalent into more of a global URL alias list outside the module graph I think having a URL scheme for it would make sense.For example what would
fetch("speifier:foo")do? Should it just take the URL from the importmap and re-fetch it? Does it expect the underlying module recoerd to also cache the response and return a clone of that?